.Net Redis Cache with support for tagging
To allow detection of cache expiry, configure redis with
config set notify-keyspace-events Ex
##Features
- Simple key value caching
- Cache item expiry
- Store cache items with tags
- Retrieve cache items by tag
- Remove all items by tag
- Multiple Serialization options
- Basic logging interface
PM> Install-Package TagCache.Redis
Any unset properties will use default values
var config = new CacheConfiguration()
{
RootNameSpace = "_RedisCache",
Serializer = new BinarySerializationProvider(),
RedisClientConfiguration = new RedisClientConfiguration()
{
Host = "localhost",
DbNo = 0,
TimeoutMilliseconds = 500
}
};
var cache = new RedisCacheProvider(config);
var cache = new RedisCacheProvider(); // will default to localhost
string key = "TagCacheTests:Add";
String value = "Hello World!";
DateTime expires = new DateTime(2099, 12, 11);
cache.Set(key, value, expires);
string key = "TagCacheTests:Add";
String value = "Hello World!";
DateTime expires = new DateTime(2099, 12, 11);
var tags = new List<string> { "tag1", "tag2", "tag3" };
cache.Set(key, value, expires, tags);
var test = cache.Get<String>("mykey");
var results = cache.GetByTag<String>("tag2");
cache.Remove("key1");
cache.Remove(new string[] { "key2", "key3" });
cache.RemoveByTag("tag1");
var cache = new RedisCacheProvider();
cache.Logger = new MyLogger(); // MyLogger : IRedisCacheLogger