Exemplo n.º 1
0
        /// <summary>
        /// Persists a CacheSet object.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cacheSet"></param>
        public async Task Cache <T>(ICacheSet <T> cacheSet, ICacheMap <T> cacheMap)
            where T : class
        {
            var setKey = cacheSet.Name;

            switch (cacheSet.Type)
            {
            case CacheType.Set:
                var cacheSetElements = cacheSet.GetSet();
                CacheSetElements(setKey, cacheSetElements, cacheMap);
                break;

            case CacheType.Hash:
                var cachedHashes = cacheSet.GetHashes();
                await CacheHashes(setKey, cachedHashes, cacheMap);

                break;

            default:
                throw new NotImplementedException("Unsupported cache type!");
            }
//            var mValue = member.GetValue(this);
//            var valType = mValue.GetType();
//            //Use the member type for mapping, instead of converting to hashmap every time..
//            if (typeof(IDictionary).IsAssignableFrom(valType))
//            {
//                var dictValueType = valType.GetGenericArguments().Skip(1).FirstOrDefault();
//                if (dictValueType != null && !dictValueType.IsPrimitive)
//                {
//                    CacheDictionary(mValue as IDictionary, member);
//                }
//                else
//                {
//                    throw new NotImplementedException();
//                }
//            }
//            else if (typeof(IEnumerable).IsAssignableFrom(valType))
//            {
//                var dictValueType = valType.GetGenericArguments().FirstOrDefault();
//                if (dictValueType != null && dictValueType.IsPrimitiveConvertable())
//                {
//                    CacheEnumerable(mValue as IEnumerable, member);
//                }
//                else
//                {
//                    throw new NotImplementedException();
//                }
//            }
            //                    var cacheReadyValue = SerializeMember(member, mValue);
            //                    _cacher.SetHash(cacheKeyBase, cacheReadyValue);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Add caches from an object that implements <see cref="ICacheSet"/>
 /// This allows maximum control over cache creation.
 /// </summary>
 /// <example>
 ///private class MyCacheSet : ICacheSet
 ///{
 ///    private ICacheBuilder myCacheBuilder = new MyCacheBuilder();
 ///    private ICacheBuilder lruBuilder = new LruCacheBuilder();
 ///
 ///    public Dictionary&lt;CacheType, ICacheOptions&gt; GetCacheConfiguration()
 ///    {
 ///        return new Dictionary&lt;CacheType, ICacheOptions&gt;()
 ///        {
 ///            { CacheType.StringsCache, new CacheOptions() { Builder = myCacheBuilder, Size = 5000 } },
 ///            { CacheType.NodesCache, new CacheOptions() { Builder = lruBuilder, Size = 15000 } },
 ///            { CacheType.ValuesCache, new CacheOptions() { Builder = lruBuilder, Size = 5000 } },
 ///            { CacheType.ProfilesCache, new CacheOptions() { Builder = null, Size = 600 } },
 ///            { CacheType.SignaturesCache, new CacheOptions() { Builder = myCacheBuilder, Size = 500 } }
 ///        };
 ///    }
 ///}
 ///
 ///public DataSet CreateDataSet()
 ///{
 ///    return DataSetBuilder.File()
 ///        .ConfigureCachesFromCacheSet(new MyCacheSet())
 ///        .Build(@"C:\datafile.dat");
 ///}
 /// </example>
 /// <param name="set">The cache set to use</param>
 /// <returns>The <see cref="DataSetBuilder"/></returns>
 public T ConfigureCachesFromCacheSet(ICacheSet set)
 {
     ConfigureCaches(set.GetCacheConfiguration());
     return((T)this);
 }