Esempio n. 1
0
        internal static CacheItem CreateCacheItem(string key, string cacheName, object value, IEnumerable <DataCacheTag> tags, bool expirable, TimeSpan timeout)
        {
            if (timeout <= TimeSpan.Zero)
            {
                throw new ArgumentException("Time-out should be a positive value.", nameof(timeout));
            }



            var dataCacheItem = new DataCacheItem
            {
                Value      = value,
                RegionName = "Default_Region",
                Version    = new DataCacheItemVersion(),
                CacheName  = cacheName,
                Key        = key.Trim()
            };

            if (tags != null && tags.Count() > 0)
            {
                dataCacheItem.Tags = new ReadOnlyCollection <DataCacheTag>(tags.ToList());
            }



            if (expirable)
            {
                dataCacheItem.Timeout = timeout;
            }
            else
            {
                dataCacheItem.Timeout = TimeSpan.MaxValue;
            }

            var cacheItem = new CacheItem(dataCacheItem);

            if (expirable)
            {
                cacheItem.Expiration = new Expiration(ExpirationType.Absolute, timeout);
            }

            return(cacheItem);
        }
Esempio n. 2
0
        internal static DataCacheItem ConvertToDataCacheItem(string key, string cacheName, CacheItem cacheItem)
        {
            var dataCacheItem = new DataCacheItem
            {
                Key        = key.Trim(),
                CacheName  = cacheName,
                RegionName = cacheItem.Group,
                Timeout    = cacheItem.Expiration.ExpireAfter,
                Value      = cacheItem.GetValue <object>(),
                Version    = new DataCacheItemVersion(cacheItem.Version)
            };

            var dataCacheTags = UnMarshalTags(cacheItem.Tags);

            if (dataCacheTags != null)
            {
                dataCacheItem.Tags = new ReadOnlyCollection <DataCacheTag>(dataCacheTags);
            }

            return(dataCacheItem);
        }
 internal DataCacheItemVersion(DataCacheItem dataCacheItem)
 {
     CreationTime = dataCacheItem.Version.CreationTime;
 }