Plan for a mixture. Plenty of places will be happy to take cards, even for small amounts but others will either be cash only or ask for cash if under a few euros.
Plus a lot of the time the buses don't take cards, it's cash or app/travel pass. It is worth investigating the latter if you plan to use the bus as there are substantial discounts (50 to 75% IME) however apps will either be in Spanish or with unhelpful translation including place names into nonsense. Or it will take a bit of time to track down the exact kiosk or tobacconist to buy the card.
As for which card, look at the Moneysavingexpert guide as charges vary according to card.
The gold standard is a card that gives you the perfect exchange rate without fees and if you don't already have one of these cards you can get one in a few days for the physical card or more or less instantly for the virtual one you can add to your phone wallet.
Worst ones charge a fee per transaction which really adds up if you use for every last coffee, beer, ice cream etc.
On cash, we tend to just hang on to euros left over from last time as we go away 3 or 4 times a year but if you need euros, I first ask around if any friends or family have any I can buy or get 50 to 100 from a UK bureau de change. Or possibly make one cash withdrawal while abroad. I've found in Spain nearly all cash machines even those at banks, charge to withdraw cash, so if you do this, do it once to limit charges. Although if you have a Santander card you can get cash without charges at Spanish Santander machines.
While that sounds like a lot of effort to save a few quid, it's an example of 'look after the pennies and the pounds will look after themselves'