New Posts New Posts RSS Feed: Code sample of an Asynchronous query to periodically refresh stale cache data
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Code sample of an Asynchronous query to periodically refresh stale cache data

 Post Reply Post Reply
Author
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post Topic: Code sample of an Asynchronous query to periodically refresh stale cache data
    Posted: 16-Jul-2007 at 2:06pm

Here is my advice regarding how to keep your cache up to date.  This advice is for a beginning strategy.  As your application becomes more mature, we can discuss additional refinements and optimizations.  Don't hesitate to call or email me if you have questions or concerns.

The basic strategy is to periodically refresh the cache by retrieving data from the database.

Simple Mechanism for Updating the Cache

We have periodically discussed using our Asynchronous Queries feature and a Push strategy, but I would start with something simpler.  I would store  a variable in session state for Last_Query_Time.  At some predictable event (e.g., Page Refresh), I would compare the current time with Last_Query_Time.  If the time interval were greater than some interval (e.g, 5 minutes).  I would requery.

What should you Query for?

You could refetch/refresh the items currently in the cache, but that's not normally what you want.  You want the recent inserts as well. What you really want to do is to make the same query (or set of queries) that you made at the beginning of your application to pick up any recent changes.  For example, if you are viewing all posts made to your website since the beginning of the year, you want to requery to see all recent posts as well.
 
Sometimes, the requery will be easy to construct, but if you have made many different queries on the same or related tables, it may not be so easy.  In some cases, if the table is fairly small, you can just requery for the entire table.
 
Ask only for Recent Data
 
One optimization that you can do is to ask for only the recent data.  In other words, if you are querying for orders, you might only ask for any order or order change in the last five minutes.  Be wary of querying for recent data from very large tables.  Databases are usually not indexed on mod time stamp, and as a result, you could have poor performance.  Try to restrict the amount of data you are requerying if you can.
 
Merge Strategy
 
You should use a MergeStrategy of OverwriteChanges
 
Back to Top
Customer View Drop Down
Senior Member
Senior Member
Avatar
User Submitted Questions to Support

Joined: 30-May-2007
Location: United States
Posts: 260
Post Options Post Options   Quote Customer Quote  Post ReplyReply Direct Link To This Post Posted: 16-Jul-2007 at 2:05pm

Is it possible to supply any examples of code for Pilotbean that show an Asynchronous query to periodically refresh stale cache data by comparing last modified time stamps.

Any details would be great!

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down