AI OnAI Off
private static IVCacheKey _versionKey;
public const string IVCacheVersion = "Moelven.Global.IVCacheVersion";
protected void Application_Start(Object sender, EventArgs e)
{
// Init _versionKey
_versionKey = new IVCacheKey("Moelven.Global.IVCacheVersion");
SetIVCacheVersion(null, null);
// Update ImageVault _versionKey
IVDataFactory.AfterAddFileEvent += SetIVCacheVersion;
IVDataFactory.AfterUpdateFileEvent += SetIVCacheVersion;
IVDataFactory.UpdateAlbumEvent += SetIVCacheVersion;
IVDataFactory.DeleteFileEvent += SetIVCacheVersion;
}
protected static void SetIVCacheVersion(object source, ImageStoreNET.CMS.Data.IVDataEventArgs e)
{
_versionKey.Value = DateTime.Now.Ticks;
}
// Properties
public static long Version
{
get
{
return _versionKey.Value;
}
}
//Internal class
internal class IVCacheKey
{
// Fields
private readonly string _keyName;
// Methods
internal IVCacheKey(string keyName)
{
_keyName = keyName;
EnsureKey();
}
internal void EnsureKey()
{
if (CacheManager.RuntimeCacheGet(_keyName) == null)
{
SetKey();
}
}
private void SetKey()
{
SetKey(DateTime.Now.Ticks);
}
private void SetKey(long value)
{
CacheManager.RuntimeCacheInsert(_keyName, value, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable);
}
internal void Update()
{
CacheManager.RuntimeCacheInsert(_keyName, DateTime.Now.Ticks, null, DateTime.MaxValue, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable);
UpdateRemoteOnly();
}
internal void UpdateRemoteOnly()
{
CacheManager.RemoveRemoteOnly(_keyName);
}
// Properties
internal string Name
{
get
{
return _keyName;
}
}
internal long Value
{
get
{
EnsureKey();
return (long)CacheManager.RuntimeCacheGet(_keyName);
}
set
{
SetKey(value);
}
}
}
// After the List of images is created
string[] dependencyKey = new string[] { Global.IVCacheVersion };
CacheDependency dependency = new CacheDependency(null, dependencyKey);
HttpContext.Current.Cache.Insert(key, imageList, dependency);
public const string IVCacheVersionKey = "Moelven.Global.IVCacheVersion"; public static long IVCacheVersion; protected void Application_Start(Object sender, EventArgs e) { // Init IVCacheVersionKey SetIVCacheVersion(null, null); // Update ImageVault IVCacheVersionKey IVDataFactory.AfterAddFileEvent += SetIVCacheVersion; IVDataFactory.AfterUpdateFileEvent += SetIVCacheVersion; IVDataFactory.UpdateAlbumEvent += SetIVCacheVersion; IVDataFactory.DeleteFileEvent += SetIVCacheVersion; } protected static void SetIVCacheVersion(object source, ImageStoreNET.CMS.Data.IVDataEventArgs e) { IVCacheVersion = DateTime.Now.Ticks; } // After the List of images is created string[] dependencyKey = new string[] {Global.IVCacheVersionKey}; CacheDependency dependency = new CacheDependency(null, dependencyKey); HttpContext.Current.Cache.Insert(key, imageList, dependency);