Exemplo n.º 1
0
        internal static void InvalidateTagsCache(string accountNameKey)
        {
            //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase();
            IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase();

            try
            {
                cache.KeyDelete(
                    ApplicationTagsHash.Key(accountNameKey),
                    CommandFlags.FireAndForget
                    );
            }
            catch
            {
            }
        }
Exemplo n.º 2
0
        public static List <string> GetTags(string accountNameKey, bool useCachedVersion = true)
        {
            //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase();
            IDatabase cache          = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase();
            string    redisHashField = ApplicationTagsHash.Fields.TagList();

            var           tags      = new List <string>();
            List <string> tagsCache = null;

            if (useCachedVersion)
            {
                try
                {
                    #region Attempt to get from Cache

                    var redisValue = cache.HashGet(ApplicationTagsHash.Key(accountNameKey), redisHashField);
                    if (redisValue.HasValue)
                    {
                        tagsCache = JsonConvert.DeserializeObject <List <string> >(redisValue);
                    }

                    #endregion
                }
                catch
                {
                }
            }

            if (tagsCache == null)
            {
                #region Retrieve and store into cache

                var account     = AccountManager.GetAccount(accountNameKey);
                var tagEntities = Internal.RetrieveTags(account.AccountID.ToString(), account.StoragePartition).ToList();

                foreach (TagTableEntity tagTableEntity in tagEntities)
                {
                    tags.Add(tagTableEntity.TagName);
                }

                tags.Sort();

                try
                {
                    //Store into "tags" Cache & set expiration
                    cache.HashSet(ApplicationTagsHash.Key(accountNameKey), redisHashField, JsonConvert.SerializeObject(tags), When.Always, CommandFlags.FireAndForget);
                    cache.KeyExpire(ApplicationTagsHash.Key(accountNameKey), ApplicationTagsHash.DefaultCacheLength, CommandFlags.FireAndForget);
                }
                catch
                {
                }

                #endregion
            }
            else
            {
                tags = tagsCache;
            }

            return(tags);
        }