1

I have form that displays several keywords (standard set of choice lists that changes rarely). There are about 4 such fields and each have about 20 choices or so.

I'm thinking if caching the keywords will be helpful for performance / best practice? Is there a strategy for determining when to cache?

3 Answers 3

1

To start, you ought to look at the cost for those keywords.

  • Are you querying them from the database, each one individually?
  • Are you querying them as a group?
  • Are they constants that you're simply writing out?

In general when optimizing (IE caching) look for items that are going to return the most bang for your buck.

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

Sign up to request clarification or add additional context in comments.

3 Comments

I forgot to mention -- they will be queried from the database and each one individually. The form will be used about 3000 times in a month and have almost the same data for the keywords. There are no constants. 5 fields = 5 separate table lookups
So how "expensive" is these queries. Do they take milliseconds to run? seconds? minutes? Typically queries are cheap. To me, this case sounds like it fits the adage "premature optimization is the root of all evil."
I agree with LFSR, at 3000 views per month, and as long as they are simple queries, I'd find better places to use cache resources.
1

You could use the ASP.NET Output Cache in your Page Directive.

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

This will create a server-side cache of the page for each Keyword GET/POST request, and each cache will last 1 minute.

So if someone visits my-page.aspx?Keyword=Cards asp.net will render the page and save 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.

Comments

0

Use a lazy initialized singeton with appropriate field to store your data. eg of this singleton at http://www.yoda.arachsys.com/csharp/singleton.html

You can have the property to be of type

"IDictionary<string, IList<string>"

if you want them organised by Category and iterable by keyword.

You can use

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

IDIctionary

if you want to be search able by category and keyword. If I read your question correctly, this would be an appropriate choice for you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.