J
J. Baute
I'm caching data in the Application object to speed up certain pages on a website
The main reason is that the retrieval of this data takes quite a while (a few seconds) and fetching the same data from the "cache" hardly takes any time
A basic pattern used to get the data from disk, or from cache is this
data = getDataFromCache("mydata"
if data = "" the
data = getDataFromDisk(
storeDataInCache(data, "mydata"
end i
Now this works fine as long as there aren't a lot of simultaneous request for this page when the cache has expired
If however the cache has expired and several request are made to the same page, each instance of this page will be taking the task upon him to recreate the cached data, which is unnecessary
I'm wondering if there's a tried and tested mechanisme for plain old ASP that handles this problem that anyone knows of. If there is, I'd be happy to find out :
A few options I can think of myself right now are
1 - create some sort of a locking system. Application.Lock/Unlock could be used for this, but that would mean that every ASP page writing something into the Application object will be put on hold for that time (there are hardly any of those pages though, but still)
2 - change my cache retrieval methods in such a way that they return the expired data anyway, and appoint the first calling page to update the cache, and simply return the old data to the other calling pages as if it hadn't expired yet
feel free to spill your comments :
The main reason is that the retrieval of this data takes quite a while (a few seconds) and fetching the same data from the "cache" hardly takes any time
A basic pattern used to get the data from disk, or from cache is this
data = getDataFromCache("mydata"
if data = "" the
data = getDataFromDisk(
storeDataInCache(data, "mydata"
end i
Now this works fine as long as there aren't a lot of simultaneous request for this page when the cache has expired
If however the cache has expired and several request are made to the same page, each instance of this page will be taking the task upon him to recreate the cached data, which is unnecessary
I'm wondering if there's a tried and tested mechanisme for plain old ASP that handles this problem that anyone knows of. If there is, I'd be happy to find out :
A few options I can think of myself right now are
1 - create some sort of a locking system. Application.Lock/Unlock could be used for this, but that would mean that every ASP page writing something into the Application object will be put on hold for that time (there are hardly any of those pages though, but still)
2 - change my cache retrieval methods in such a way that they return the expired data anyway, and appoint the first calling page to update the cache, and simply return the old data to the other calling pages as if it hadn't expired yet
feel free to spill your comments :