예제 #1
0
 internal static void InvalidateImageFormatCaches(string accountNameKey)
 {
     try
     {
         //Switch to Application specific redis server?
         //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase();
         IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase();
         cache.KeyDelete(ApplicationImageFormatsHash.Key(accountNameKey));
     }
     catch
     {
     }
 }
        public static List <ImageFormatGroupModel> GetImageFormats(string accountNameKey, string imageFormatGroupTypeNameKey)
        {
            List <ImageFormatGroupModel> imageGroups = null;

            string cacheKey   = ApplicationImageFormatsHash.Key(accountNameKey);
            string cacheField = ApplicationImageFormatsHash.Fields.AllFormatsByGroupType(imageFormatGroupTypeNameKey);

            //IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.AccountManager_Multiplexer.GetDatabase();
            IDatabase cache = Sahara.Core.Settings.Azure.Redis.RedisMultiplexers.RedisMultiplexer.GetDatabase();

            #region Get propertyTypes from cache

            try
            {
                var redisValue = cache.HashGet(cacheKey, cacheField);
                if (redisValue.HasValue)
                {
                    imageGroups = JsonConvert.DeserializeObject <List <ImageFormatGroupModel> >(redisValue);
                }
            }
            catch
            {
            }

            if (imageGroups == null)
            {
                #region Get categories from SQL

                var account = AccountManager.GetAccount(accountNameKey, true, AccountManager.AccountIdentificationType.AccountName);

                imageGroups = Sql.Statements.SelectStatements.SelectImageFormatsByGroupType(account.SqlPartition, account.SchemaName, imageFormatGroupTypeNameKey);

                #endregion

                #region Store count into cache

                try
                {
                    cache.HashSet(cacheKey, cacheField, JsonConvert.SerializeObject(imageGroups), When.Always, CommandFlags.FireAndForget);
                }
                catch
                {
                }

                #endregion
            }

            return(imageGroups);

            #endregion
        }