I've created a custom resource provider which returns strings from our database to use for whatever.
The issue is I haven't found a way to "bust" the cache on these items and reload them from the database. Ideally I'd do this every x minutes or manually when we update the cache and want to reload it.
Technically, that's easy. I'm storing everything in a hashtable so just nuke that and reload when needed. However since the ResourceProviderFactory handles the loading of each resource class and I'm not sure how to enumerate the classes it has created.
An overview of the code:
public class ResourceProvider : IResourceProvider
{
private Dictionary<string, Dictionary<string, object>> _resourceCache
= new Dictionary<string, Dictionary<string, object>>();
private string _virtualPath;
private string _className;
public ResourceProvider(string virtualPath, string className)
{
_virtualPath = virtualPath;
_className = className;
}
public object GetObject(string resourceKey, CultureInfo culture)
{
...
}
}
public class ResourceProviderFactory :System.Web.Compilation.ResourceProviderFactory
{
public override IResourceProvider CreateGlobalResourceProvider(string classKey)
{
return new Cannla.Business.Resource.ResourceProvider(string.Empty, classKey);
}
...
...
}
What I was planning to do was add a reference every time CreateGlobalResourceProvider is called (e.g. add the new object to a collection and then enumerate that and nuke everything inside that object when I need to) but I'm unsure if this is going to do something weird to the ResourceProviderFactory.
Is there any ResourceProviderFactory IEnumerable method or something that will give me all those objects in a easy way before I go building all this code?