Search code examples
c#asp.netdatabasecachingcookies

ASP.NET : how can I store a list of strings for a certain period of time to avoid an unnecessary number of requests to the database?


I want to temporarily (maybe 5-10 minutes) store a list of strings somehow, so that the database doesn't get queried every single time this list is needed in a short period of time by a user.

I've tried looking into it, and from what I've read, cookies are supposed to be used for user preferences rather than storing content for the website, and cache doesn't expire automatically (I want it to expire after 5-10 min), but I may be misinterpreting something here. Basically, I would like to know how to temporarily store data for a set amount of time so I can avoid repeatedly asking the database for the exact same information in a short period of time.

Sorry if this is a dumb question; I've never used these before and there's a lot of terminology I don't understand.


Solution

  • It seems like you are looking for Caching. Cache is a high-speed data storage layer which stores a subset of data. Moreover, you can set the period at which it expires.

    The following sources will provide a good starting point: