Results 1 to 5 of 5

Thread: Static Caching

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Static Caching

    Hi There,

    Is there anyone here who can explain me the concept of a static caching.because i will implement it with my menu structure in my project..
    i will cache the structure of my menu which is came from a database.

    Thanks in advance.
    glen

  2. #2
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Static Caching

    well do you know what caching is?
    caching is a way to hold in memory, the data you will be obtaining or querying against, rather than hitting the database all the time or a webservice or something else.

    how did you come to the conclusion you need "caching"?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: Static Caching

    Hi Techno,

    i came up with that solution because my database is in remote area.so i would like to cache the structure of my menu (e.g File,View,Edit etc. including submenus).since my menus will not often change.so,i think this is a good candidate for caching..

    can you guide me how to start with these?

    thanks
    glen

  4. #4
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Static Caching

    here is some pseudo logic:

    if collection of menus is empty, then populate from DB


    then everytime you need to access the menu, instead of reading from the DB, read from the collection.
    to me, its still unclear at what point you would be accessing the menus and why in cache even if they wont change that often.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Static Caching

    Regardless of whether or not this is a good idea, let's look at how the structure of your app would change. Let's say that, at the moment. The application makes a call to the database to get the data and displays it. The first step would be to create a class to sit in the middle of that operation. The app makes a call to that class, which will act as the cache, and the class makes the call to the database and returns the data.

    The next step would be to, in this new class, store the data in appropriate member variables when it is retrieved from the database. That local store is the actual cache.

    Now, the final step is, as Techno said, to change your cache class so that it first tests that local store for the data. If the local store is empty it makes a call to the database to populate it. Finally, the data in the local store is returned. In pseudo-code, a call to your cache class might look something like this:
    csharp Code:
    1. object data;
    2.  
    3. public object GetData()
    4. {
    5.     if (data == null)
    6.     {
    7.         data = RetrieveData();
    8.     }
    9.  
    10.     return data;
    11. }
    You might also get a bit fancier and put an expiration time on your cache. To do that you would set a DateTime variable each time you retrieved the data. The next time a call for the data is made you would check how much time has passed since the last refresh and, if it is longer than a specific limit, retrieve the data again regardless.

    Remember that your cache can be as complex as you like. It doesn't have to be just one field and you don't have to get all the cached data in one go. For instance, if you're caching two database tables then you would only get the data for each when an actual request for that data was made. The user might request one table many times before requesting the second or they may not request the second at all, so you don't get the data for the second table until they request it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width