The ones run by younger people are very credit-card-first, love not dealing with cash, etc. They usually have one of those Stripe iPad things. If you do pay with cash, they'll get a bit flustered because it breaks their flow.
The ones run by older people are either cash-only or try hard to disincentivize customers from using credit cards, sometimes with signs guilting customers about how much money card companies take from businesses.
It really feels like a generational thing depending on what people are used to. The older shop owners remember when cards were a lot more rare, and they've seen their swipe fee expenditure go up over the years. While the younger owners have only ever lived in a credit card oriented world and just bake the swipe fees into their prices from the beginning.
For food, most places will accept cash here. Hell, even a bookstore near me won't accept cash anymore.
If the store was extending you credit (ie leave now with the goods and in the future pay us back) they’d be required to accept cash at that point.
That said, there are laws in some jurisdictions against card-only payment policies. I suspect they're not widely enforced for smaller places.
There is no federal statute mandating that a private business, a person, or an organization must accept currency or coins as payment for goods or services.
(There are some specific local laws; generally though it appears not to be the case that you have to accept cash.)
Article I, Section 10, Clause 1:
No State shall enter into any Treaty, Alliance, or Confederation; grant Letters of Marque and Reprisal; coin Money; emit Bills of Credit; make any Thing but gold and silver Coin a Tender in Payment of Debts; pass any Bill of Attainder, ex post facto Law, or Law impairing the Obligation of Contracts, or grant any Title of Nobility.
Variously interpreted, that part about states can't make their own currency may be tangentially important.
I also saw that places like gas stations "pre pay" if I select debit, trying to hold $60-$100 from my bank account until the final transaction comes back.
While this hasn't happened to me, I've read that if your debit card is compromised or if a charge back is required, you would have to fight your bank to get your money back and it's a bit easier with credit cards.