Ent Lib 4.1 Caching Block - expiration issues

Topics: Caching Application Block
Feb 19, 2010 at 4:03 PM
Edited Feb 19, 2010 at 4:06 PM

I have a web service that uses the Caching block to save snapshots of data from our database as DataSets.  I want it to expire and refresh every 60 minutes.  This service exposes a set of methods to allow applications to retrieve the desired DataSet from the Service.  The applications in turn cache the results from the Service via the same code base, but via in process calls.  No matter how I configure the CacheManager.Add methods in the service or in the calling app I can not get the desired expiration and refresh.  I am using the ICacheItemRefreshAction.Refresh method to re-add the DataSet to the CacheManager.  expirationPollFrequencyInSeconds is set to the default of 60.  I have tried many scenarios, the latest I am trying is an expiration at 15 minutes after the hour.  This has worked the best so far except for some odd behavior.  Both instances caches (service/app) update at 15 after the hour to begin with, and will continue to do so as long as they are accessed within the next 60 minutes.  If they are not accessed within 60 minutes of the last refresh they stop refreshing, until they get accessed again.

cacheManager.Add(key, dataSet,CacheItemPriority.Normal, new RefreshAction(), new ExtendedFormatTime("15 * * * *"));

I have also tried implementing AbsoluteTime instead of ExtendedFormatTime, but the results were even stranger.  If someone can shed some light on how the expiration process works and needs to be configured I would really appreciate it.  Everything I have read makes it all sound so simple.  But I have tried every scenario I can think of and can not get the desired behavior.  I just want the cache to refresh once an hour every hour.  Not once an hour and every time the cache is retrieved.  Or any other way.

 

Feb 20, 2010 at 6:02 AM

Let me rephrase your inquiry if I get it right... you want to implement caching in your webservice using Enterprise Library 4.1 caching block that retrieves a dataset from your data store, and you wish to happen this caching once per hour, irregardless whether they are access or not.

Feb 20, 2010 at 6:07 AM

your statement "If they are not accessed with 60 minutes of the last refresh, they stop refreshing until they get accessed again", does it mean if "no one" access the application, the cache does not refresh until the application is accessed again?

Feb 20, 2010 at 6:58 AM

by the way, how did you pass to the ICacheItemRefreshAction.Refresh method the cache manager? Did you use a public static object to handle the cache manager?

Feb 22, 2010 at 7:08 PM

Yes, I want the cache to refresh once an hour regardless of whether it was accessed or not.  Your question "does it mean if "no one" access the application, the cache does not refresh until the application is accessed again?", yes that is correct.

Are you asking how the cacheManager object in the cacheManager.Add statement is instantiated?  If so it is a private variable that is accessed from a public class.  Neither is static.

Feb 23, 2010 at 9:15 AM

I made a simple repro of your scenario, I added an item to the cache that expires every minute and set the expirationPollFrequencyInSeconds to 60 but I'm getting the Refresh action as expected.  I'm curious as to what happens if you use AbsoluteTimeExpiration.  Can you describe it?

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Feb 23, 2010 at 7:39 PM

Let me try to clarify a little the problems I am running into.  I have two caches, one is accessed from a Web Service.  The Web Service pulls data from a database and caches.  The second cache is internal to an application.  The application uses its internal cache, until such time as that cache expires.  Then it calls the Web Service to get an update.  The problems I am seeing relate to actions in the Application cache causing events to occur in the Web Service cache.  I can give more specific details tomorrow, but here are some specifics about the configuration.

Both the application and service are running on the same server.

Both the application and Service use the same keys in the cache.

The Application and Service have different CacheManager names.

Phil Fitzgerald

From: AvanadeSupport [mailto:notifications@codeplex.com]
Sent: Tuesday, February 23, 2010 5:16 AM
To: Phil Fitzgerald
Subject: Re: Ent Lib 4.1 Caching Block - expiration issues [entlib:85971]

From: AvanadeSupport

I made a simple repro of your scenario, I added an item to the cache that expires every minute and set the expirationPollFrequencyInSeconds to 60 but I'm getting the Refresh action as expected. I'm curious as to what happens if you use AbsoluteTimeExpiration. Can you describe it?

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

STATEMENT OF CONFIDENTIALITY

The information contained in this electronic message, and any attachments to this
message, are intended for the exclusive use of the intended recipients and may contain
confidential and privileged information.  Any unauthorized review, use, disclosure or
distribution of this email message or its attachments is prohibited.  If you are not
the intended recipient, please notify Intersections Inc. at security@intersections.com,
and then destroy all copies of this message and any attachments.
Feb 24, 2010 at 7:05 PM

Using AbsoluteTime Expiration with the following parameters;

Service

expirationPollFrequencyInSeconds 60

duration 660 (11 minutes)

App

expirationPollFrequencyInSeconds 60

duration 420 (7 minutes)

I see the following behavior;

I make an initial request to the App, which in turn causes a check of its cache.

The cache is empty, so it makes a call to the Service.

The Services cache is empty, so it makes a call to the database.

The service cache gets loaded and returns the result to the App.

The apps cache gets loaded.

The cache now never refreshes, not the App at 7 minutes or the Service at 11 minutes.

If I again make a request to the app the process outlined above repeats.

If I make another request before 7 minutes is up, cache is returned from memory.

If the request is between the 7th minute and the 11th minute, then the app calls to the Service to get an update.

The service returns data from memory.

If the request is after the 11 minute window, the service gets the data from the database and updates its cache.  Then it returns it to the app.

The app then refreshes with the result from the Service.

This causes serial impacts to my processing.  I want the service to update itself every 11 minutes no matter what in this scenario.

I want the app to refresh every 7 minutes.  I never want the App to be waiting on the service to call to the database.

Please let me know your thoughts on this.

Thanks,

Phil Fitzgerald

From: Phil Fitzgerald
Sent: Tuesday, February 23, 2010 3:27 PM
To: 'entlib@discussions.codeplex.com'
Subject: RE: Ent Lib 4.1 Caching Block - expiration issues [entlib:85971]

Let me try to clarify a little the problems I am running into. I have two caches, one is accessed from a Web Service. The Web Service pulls data from a database and caches. The second cache is internal to an application. The application uses its internal cache, until such time as that cache expires. Then it calls the Web Service to get an update. The problems I am seeing relate to actions in the Application cache causing events to occur in the Web Service cache. I can give more specific details tomorrow, but here are some specifics about the configuration.

Both the application and service are running on the same server.

Both the application and Service use the same keys in the cache.

The Application and Service have different CacheManager names.

Phil Fitzgerald

From: AvanadeSupport [mailto:notifications@codeplex.com]
Sent: Tuesday, February 23, 2010 5:16 AM
To: Phil Fitzgerald
Subject: Re: Ent Lib 4.1 Caching Block - expiration issues [entlib:85971]

From: AvanadeSupport

I made a simple repro of your scenario, I added an item to the cache that expires every minute and set the expirationPollFrequencyInSeconds to 60 but I'm getting the Refresh action as expected. I'm curious as to what happens if you use AbsoluteTimeExpiration. Can you describe it?

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

STATEMENT OF CONFIDENTIALITY

The information contained in this electronic message, and any attachments to this
message, are intended for the exclusive use of the intended recipients and may contain
confidential and privileged information.  Any unauthorized review, use, disclosure or
distribution of this email message or its attachments is prohibited.  If you are not
the intended recipient, please notify Intersections Inc. at security@intersections.com,
and then destroy all copies of this message and any attachments.
Feb 24, 2010 at 8:43 PM

After a few hours I started getting these errors;

System.ArgumentOutOfRangeException: Absolute time cannot be less than current time.”

I was using,

new AbsoluteTime(TimeSpan.FromSeconds(this.__duration)));

I have now changed to using;

new AbsoluteTime(DateTime.UtcNow.AddSeconds(this.__duration)));

But now my cache is refreshing every time every 60 seconds, it seems to always be expired.

Phil Fitzgerald

From: Phil Fitzgerald
Sent: Wednesday, February 24, 2010 2:56 PM
To: Phil Fitzgerald; 'entlib@discussions.codeplex.com'
Subject: RE: Ent Lib 4.1 Caching Block - expiration issues [entlib:85971]

Using AbsoluteTime Expiration with the following parameters;

Service

expirationPollFrequencyInSeconds 60

duration 660 (11 minutes)

App

expirationPollFrequencyInSeconds 60

duration 420 (7 minutes)

I see the following behavior;

I make an initial request to the App, which in turn causes a check of its cache.

The cache is empty, so it makes a call to the Service.

The Services cache is empty, so it makes a call to the database.

The service cache gets loaded and returns the result to the App.

The apps cache gets loaded.

The cache now never refreshes, not the App at 7 minutes or the Service at 11 minutes.

If I again make a request to the app the process outlined above repeats.

If I make another request before 7 minutes is up, cache is returned from memory.

If the request is between the 7th minute and the 11th minute, then the app calls to the Service to get an update.

The service returns data from memory.

If the request is after the 11 minute window, the service gets the data from the database and updates its cache. Then it returns it to the app.

The app then refreshes with the result from the Service.

This causes serial impacts to my processing. I want the service to update itself every 11 minutes no matter what in this scenario.

I want the app to refresh every 7 minutes. I never want the App to be waiting on the service to call to the database.

Please let me know your thoughts on this.

Thanks,

Phil Fitzgerald

From: Phil Fitzgerald
Sent: Tuesday, February 23, 2010 3:27 PM
To: 'entlib@discussions.codeplex.com'
Subject: RE: Ent Lib 4.1 Caching Block - expiration issues [entlib:85971]

Let me try to clarify a little the problems I am running into. I have two caches, one is accessed from a Web Service. The Web Service pulls data from a database and caches. The second cache is internal to an application. The application uses its internal cache, until such time as that cache expires. Then it calls the Web Service to get an update. The problems I am seeing relate to actions in the Application cache causing events to occur in the Web Service cache. I can give more specific details tomorrow, but here are some specifics about the configuration.

Both the application and service are running on the same server.

Both the application and Service use the same keys in the cache.

The Application and Service have different CacheManager names.

Phil Fitzgerald

From: AvanadeSupport [mailto:notifications@codeplex.com]
Sent: Tuesday, February 23, 2010 5:16 AM
To: Phil Fitzgerald
Subject: Re: Ent Lib 4.1 Caching Block - expiration issues [entlib:85971]

From: AvanadeSupport

I made a simple repro of your scenario, I added an item to the cache that expires every minute and set the expirationPollFrequencyInSeconds to 60 but I'm getting the Refresh action as expected. I'm curious as to what happens if you use AbsoluteTimeExpiration. Can you describe it?

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

STATEMENT OF CONFIDENTIALITY

The information contained in this electronic message, and any attachments to this
message, are intended for the exclusive use of the intended recipients and may contain
confidential and privileged information.  Any unauthorized review, use, disclosure or
distribution of this email message or its attachments is prohibited.  If you are not
the intended recipient, please notify Intersections Inc. at security@intersections.com,
and then destroy all copies of this message and any attachments.