Hi there

 

The first limitation anyone will feel from Azure Redis Cache API is the need of converting any value in a string

I made another implementation of my common CacheManager object to access easily such Redis cache in fluent way

Available on NuGet with the name of TNX.Cache.Redis, the package definitely helps in serialization/deserialization work adding a comfortable fluent API

here an example

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using TNX.CacheManager.Redis;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var myConnectionString = “[NAME].redis.cache.windows.net,ssl=true,password=[KEY]”;

//cache setup
//connection string
CacheManager.RedisConnectionString = myConnectionString;

//set the short-lived object lifetime (default 1) used by GetOrDrillShort method
CacheManager.ShortRetentionMinutes = 1; //as default

//set the long-lived object lifetime (default 30) used by GetOrDrillLong method
CacheManager.LongRetentionMinutes = 30; //as default

//I can enable tracing
CacheManager.EmitsDebugTrace = false; //disabled

while (true)
{
DateTime time = CacheManager.GetOrDrill<DateTime>(OnCacheRedrill, TimeSpan.FromSeconds(5), “key”, “sub-key”);

Console.WriteLine(“{0}”, time);
Thread.Sleep(1000);
}
}

private static DateTime OnCacheRedrill()
{
return DateTime.Now;
}
}
}

Lascia un commento