1
Vote

DynamicImage - Require greater control over DynamicImageProvider's Caching

description

In particular, I'm using a custom IImageCreator to manage images generated from the database (as per the sample).
 
I want to use Server caching (with the fixed timeout is OK) but I also need to be able to expire the cache potentially sooner (when a new image is uploaded over the top).
 
To resolve, I would at least suggest two virtual methods inside DynamicImageProvider:
 
protected virtual void OnCacheItemExpired(string key, object value, CacheItemRemovedReason reason)
{
return;
}
 
protected virtual CacheDependency GetCacheDependency(NameValueCollection parameters)
{
return null;
}
 
And then update the cache add block (line 513 in source code release 18578) to use these:
 
this.Context.Cache.Add(
this.ServerCacheKey,
cacheItem,
GetCacheDependency(Parameters),
DateTime.Now.AddMinutes(serverCacheDuration),
TimeSpan.Zero,
CacheItemPriority.Normal,
OnCacheItemExpired);
 
This way, I can implement an inherited provider class that looks for specific variables in my Parameters collection (e.g. the unique ID of the database record that owned the image) in order to expose a mechanism to expire the cache items for those dynamic images on update of the database.
 
Am happy to work with other ideas, but that's just one that involved the least update to original source code...

comments