Exemplo n.º 1
0
        public static void UpdateValue(string key, string value)
        {
            //invalidate the cache value for the key
            IDatabase cache = CacheService.Connection.GetDatabase();

            cache.KeyDelete(key);

            //update the value in the datasource
            FakeDataSource.UpdateValueToDataSource(key, value);
        }
Exemplo n.º 2
0
        public static string GetValue(string key)
        {
            string value = string.Empty;

            //get the value from the cache
            IDatabase  cache        = CacheService.Connection.GetDatabase();
            RedisValue valueInCache = cache.StringGet(key);

            if (valueInCache.HasValue) //value is in the cache
            {
                value = valueInCache.ToString();
            }
            else //value is not in the cache
            {
                //get value from datasource
                value = FakeDataSource.GetValueFromDataSource(key);

                //set value in cache
                cache.StringSet(key, value);
            }

            return(value);
        }