This project has moved. For the latest updates, please go here.

Custom Cache Policy?

Jan 21, 2012 at 4:10 PM

First of all, congratulations for this great piece of work, this makes developing apps so much more easy and fun.

I'm currently looking for a cache policy mixed of CacheThenRefresh and ValidCacheOnly. In detail this policy would use two timestamps and looks as follows:

Return cached data if not older than e.g. 1 day (ValidCachePolicy) and kick off a refresh if data is older than e.g. 10 minutes (CacheThenRefresh)

So speaking of best practice, how can this scenario be achieved?

  1. Use CacheThenRefresh with 10 minutes, manually check if data is older than 1 day and then clear the data?
  2. Use ValidCacheOnly with 1 day and manually trigger a refresh if data is older than 10 minutes?
  3. Write my own cache policy (not sure if a second timestamp fits within the existing code structure)?

Many thanks in advance!

Coordinator
Jan 24, 2012 at 7:43 PM

Hi -

Thanks for the kind words, glad you're finding it useful!

AgFx doesn't have much pluggabiity for custom cache policies, so I don't think that's the best method.

I think (1) works fine, another way you could do this is in your Deserialize method, where you would look at the timestamp on the data and just throw if the timestamp is older than a day.  You'd use CacheThenRefresh(10 minutes) here.

If your webservice doesn't have a good timestamp in the original data (because there's no direct way in Deserialize to differentiate between a cache read and a live read), then you can do a couple of things.   Probably the most reliable would be to write a custom LoadRequest that injects a timestamp into the stream somehow.  Then, in Deserialize, as I mention above, you'd just throw if the data is older than a day.  

Another way is to set an AutoRefresh time of 10 minutes, but that might not give you exactly what you want.  What you could do here is have a timer in your app that fires every 10 minutes, does a Load on the data, and if it comes back older than 10 minutes, calls Refresh on it.

There's probably some more ways to do this as well, those are the ones that I think of off the top of my head.

Shawn

Jan 24, 2012 at 11:54 PM

About this subject i have a question shawn, ICachedItem let's me set  the exipiration date of my vm.. this is good.But how about cachepolicy how can i set the attribute , let's say i want to readit from a file , and then override that file from the server, this way i can tweak the cache policy and the time for cache remotly. Should i user reflection or something like that on my constructor? 

if i understand Icacheitem interface let's me set the CacheTimeInSeconds right? how about getting the same for CachePolicy ?

Jan 26, 2012 at 8:16 PM

Thanks Shawn, will give #1 a try!

Alex