Caching with ASP.NET

I have a form that displays multiple keywords (a standard set of select lists that rarely change). There are about 4 such fields, and each of them has about 20 options or so.

I think keyword caching will be useful for efficiency / best practice? Is there a strategy for determining the caching time?

+1


source to share


3 answers


To get started, you have to look at the cost of those keywords.

  • Are you querying them from the database, one at a time?
  • Are you requesting them as a group?
  • Are these constants that you just write?


In general, optimizations (IE caching) look for items that will return the biggest bang for your dollar.

Also look at the old 80-20 rule; ~ 80 items is a small drop in the bucket, while the list of 800,000 items is worth looking at.

+1


source


You can use ASP.NET Output Cache in your Page Directive.

 <%@ OutputCache Duration="60" VaryByParam="Keyword" %>

      



This will create a server side cache for every GET / POST request for a keyword, and each cache will last 1 minute.

So, if someone visits my-page.aspx?Keyword=Cards

, asp.net will render the page and store it in memory as HTML for 60 seconds. If someone visits my-page.aspx?Keyword=Books

, it will create a separate version of the page in HTML and cache it as well.

+1


source


Use a lazy initialized sington with an appropriate field to store your data. for example this singleton at http://www.yoda.arachsys.com/csharp/singleton.html

You can have a property like

"IDictionary<string, IList<string>"

      

if you want them to be organized by category and iterable by keywords.

you can use

"IDIctionary<string, IDictionary<string, string>"

      

IDictionary

if you want the search to be performed by categories and keywords. If I read your question correctly, this would be the right choice for you.

0


source







All Articles