Assets/Watson/Scripts/Utilities/Utility.cs
/// <summary>
/// Save value to data cache.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="dictionaryCache"></param>
/// <param name="cacheDirectoryId"></param>
/// <param name="cacheId"></param>
/// <param name="objectToCache"></param>
/// <param name="prefix"></param>
/// <param name="maxCacheSize"></param>
/// <param name="maxCacheAge"></param>
Save value to data cache.
Save value to data cache .
public static void SaveToCache<T>(Dictionary<string,DataCache> dictionaryCache, string cacheDirectoryId, string cacheId, T objectToCache, string prefix="", long maxCacheSize = 1024 * 1024 * 50, double maxCacheAge = 24 * 7) where T : class, new()
        {
            if (objectToCache != null)
            {
                DataCache cache = null;
                if (!dictionaryCache.TryGetValue(cacheDirectoryId, out cache))
                {
                    cache = new DataCache( prefix + cacheDirectoryId, maxCacheSize: maxCacheSize, maxCacheAge: double.MaxValue);   
                    dictionaryCache[ cacheDirectoryId ] = cache;
                }
                fsData data = null;
                fsResult r = sm_Serializer.TrySerialize(objectToCache.GetType(), objectToCache, out data);
                if (!r.Succeeded)
                    throw new WatsonException(r.FormattedMessages);
                cache.Save(cacheId, Encoding.UTF8.GetBytes(fsJsonPrinter.PrettyJson(data)));
            }
        }
public static void SaveToCache < T > ( Dictionary < string , DataCache > dictionaryCache , string cacheDirectoryId , string cacheId , T objectToCache , string prefix = " " , long maxCacheSize = 1024 * 1024 * 50 , double maxCacheAge = 24 * 7 ) where T : class , new ( ) { if ( objectToCache != null ) { DataCache cache = null ; if ( ! dictionaryCache . TryGetValue ( cacheDirectoryId , out cache ) ) { cache = new DataCache ( prefix + cacheDirectoryId , maxCacheSize : maxCacheSize , maxCacheAge : double . MaxValue ) ; dictionaryCache [ cacheDirectoryId ] = cache ; } fsData data = null ; fsResult r = sm_Serializer . TrySerialize ( objectToCache . GetType ( ) , objectToCache , out data ) ; if ( ! r . Succeeded ) throw new WatsonException ( r . FormattedMessages ) ; cache . Save ( cacheId , Encoding . UTF8 . GetBytes ( fsJsonPrinter . PrettyJson ( data ) ) ) ; } }
Save value to data cache.
Save value to data cache .
//We will store the values as max time
dictionaryCache
Dictionary<string,DataCache>
None
cacheDirectoryId
string
None
cacheId
string
None
objectToCache
T
None
prefix
string
None
maxCacheSize
long
None
maxCacheAge
double
None
typeparam
None