Created
March 24, 2017 09:02
-
-
Save jamesikanos/041abe225b6099515691d52b5fb40f21 to your computer and use it in GitHub Desktop.
Extended Redis Cache Handle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExtendedRedisCacheHandle : CacheManager.Redis.RedisCacheHandle<string> | |
{ | |
private const string BaseRegion = "Base"; | |
private readonly string _extraRegionName; | |
public ExtendedRedisCacheHandle(ICacheManagerConfiguration managerConfiguration, CacheHandleConfiguration configuration, | |
ILoggerFactory loggerFactory, ICacheSerializer serializer) | |
: base(managerConfiguration, configuration, loggerFactory, serializer) | |
{ | |
_extraRegionName = managerConfiguration.BackplaneChannelName ?? BaseRegion; | |
} | |
private string CreateRegion(string region = null) | |
{ | |
if (string.IsNullOrEmpty(region)) | |
region = "base"; | |
return $"{_extraRegionName}_{region}"; | |
} | |
protected override bool AddInternal(CacheItem<string> item) | |
{ | |
var newItem = new CacheItem<string>(item.Key, CreateRegion(item.Region), item.Value, item.ExpirationMode, item.ExpirationTimeout); | |
return base.AddInternal(newItem); | |
} | |
protected override bool AddInternalPrepared(CacheItem<string> item) | |
{ | |
var newItem = new CacheItem<string>(item.Key, CreateRegion(item.Region), item.Value, item.ExpirationMode, item.ExpirationTimeout); | |
return base.AddInternalPrepared(newItem); | |
} | |
protected override CacheItem<string> GetCacheItemInternal(string key, string region) | |
{ | |
return base.GetCacheItemInternal(key, CreateRegion(region)); | |
} | |
protected override CacheItem<string> GetCacheItemInternal(string key) | |
{ | |
return base.GetCacheItemInternal(key, CreateRegion()); | |
} | |
protected override void PutInternal(CacheItem<string> item) | |
{ | |
var newItem = new CacheItem<string>(item.Key, CreateRegion(item.Region), item.Value, item.ExpirationMode, item.ExpirationTimeout); | |
base.PutInternal(newItem); | |
} | |
protected override void PutInternalPrepared(CacheItem<string> item) | |
{ | |
var newItem = new CacheItem<string>(item.Key, CreateRegion(item.Region), item.Value, item.ExpirationMode, item.ExpirationTimeout); | |
base.PutInternalPrepared(newItem); | |
} | |
protected override bool RemoveInternal(string key) | |
{ | |
return base.RemoveInternal(key, CreateRegion()); | |
} | |
protected override bool RemoveInternal(string key, string region) | |
{ | |
return base.RemoveInternal(key, CreateRegion(region)); | |
} | |
public override void ClearRegion(string region) | |
{ | |
base.ClearRegion(CreateRegion(region)); | |
} | |
public override void Clear() | |
{ | |
base.ClearRegion(CreateRegion()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment