コード例 #1
0
 /// <summary>
 ///     Create a new request for the specified type. The domain description will be empty
 /// </summary>
 public EvictionSetupRequest(string fullTypeName, EvictionType evictionType, int limit = 0, int itemsToEvict = 0)
     : base(DataAccessType.Write, fullTypeName)
 {
     Type         = evictionType;
     Limit        = limit;
     ItemsToEvict = itemsToEvict;
 }
コード例 #2
0
        public static EvictionPolicy Create(IPayloadReader reader)
        {
            EvictionType type = (EvictionType)reader.ReadByte("Type");

            EvictionPolicy result;

            switch (type)
            {
            case EvictionType.None:
                return(null);

            case EvictionType.BySize:
                result = new CollectionSizePolicy();
                break;

            case EvictionType.ByTime:
                result = new ObjectExpirationPolicy();
                break;

            default:
                throw new NotSupportedException();
            }
            result.Deserialize(reader);
            return(result);
        }
コード例 #3
0
 /// <summary>
 ///     Create a new request for the specified type. The domain description will be empty
 /// </summary>
 public EvictionSetupRequest(string collectionName, EvictionType evictionType, int limit = 0, int itemsToEvict = 0, int timeToLiveInMilliseconds = 0)
     : base(DataAccessType.Write, collectionName)
 {
     Type                     = evictionType;
     Limit                    = limit;
     ItemsToEvict             = itemsToEvict;
     TimeToLiveInMilliseconds = timeToLiveInMilliseconds;
 }
コード例 #4
0
        /// <summary>
        /// Only used in cache-only mode (no persistence). Can activate Less Recently Used eviction for a data type.
        /// When the <paramref name="limit"/> is reached the less recently used  <paramref name="itemsToRemove"/> items are evicted
        /// </summary>
        /// <param name="evictionType"></param>
        /// <param name="limit"></param>
        /// <param name="itemsToRemove"></param>
        public void ConfigEviction(EvictionType evictionType, int limit, int itemsToRemove = 100)
        {
            if (evictionType == EvictionType.LessRecentlyUsed && limit == 0)
            {
                throw new ArgumentException("If LRU eviction is used, a positive limit must be specified");
            }

            _client.ConfigEviction(typeof(T).FullName, evictionType, limit, itemsToRemove);
        }
コード例 #5
0
        /// <summary>
        ///     Only used in cache-only mode (no persistence). Eviction is activated by collection.
        ///     Two types of eviction are supported for now: LRU (Less Recently Used) or TTL (Time To Live)
        ///     In LRU mode the
        ///     <param name="limit"></param>
        ///     and
        ///     <param name="itemsToRemove"></param>
        ///     are used
        ///     In TTL mode only
        ///     <param name="timeLimitInMilliseconds"></param>
        ///     is used
        ///     When the <paramref name="limit" /> is reached the less recently used  <paramref name="itemsToRemove" /> items are
        ///     evicted
        /// </summary>
        /// <param name="evictionType">LRU or TTL</param>
        /// <param name="limit">threshold that triggers the eviction in LRU mode</param>
        /// <param name="itemsToRemove">number of items to be evicted when the threshold is reached in LRU mode</param>
        /// <param name="timeLimitInMilliseconds">items older than the specified value are evicted in TTL mode</param>
        public void ConfigEviction(EvictionType evictionType, int limit, int itemsToRemove = 100,
                                   int timeLimitInMilliseconds = 0)
        {
            if (evictionType == EvictionType.LessRecentlyUsed && limit == 0)
            {
                throw new ArgumentException("If LRU eviction is used, a positive limit must be specified");
            }

            _client.ConfigEviction(_collectionName, evictionType, limit, itemsToRemove, timeLimitInMilliseconds);
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fullTypeName"></param>
        /// <param name="evictionType"></param>
        /// <param name="limit"></param>
        /// <param name="itemsToRemove"></param>
        public void ConfigEviction(string fullTypeName, EvictionType evictionType, int limit, int itemsToRemove)
        {
            var request = new EvictionSetupRequest(fullTypeName, evictionType, limit, itemsToRemove);

            var response = Channel.SendRequest(request);

            if (response is ExceptionResponse exResponse)
            {
                throw new CacheException("Error while declaring a domain", exResponse.Message, exResponse.CallStack);
            }
        }
コード例 #7
0
        public void ConfigEviction(string fullTypeName, EvictionType evictionType, int limit, int itemsToRemove)
        {
            try
            {
                // the limit is global to the cluster
                var limitByNode  = limit / CacheClients.Count;
                var removeByNode = itemsToRemove / CacheClients.Count + 1;

                Parallel.ForEach(CacheClients, client => client.ConfigEviction(fullTypeName, evictionType, limitByNode, removeByNode));
            }
            catch (AggregateException e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }
            }
        }
コード例 #8
0
ファイル: CacheClient.cs プロジェクト: lanicon/Cachalot
        /// <summary>
        /// </summary>
        /// <param name="fullTypeName"></param>
        /// <param name="evictionType"></param>
        /// <param name="limit"></param>
        /// <param name="itemsToRemove"></param>
        /// <param name="timeLimitInMilliseconds"></param>
        public void ConfigEviction(string fullTypeName, EvictionType evictionType, int limit, int itemsToRemove, int timeLimitInMilliseconds = 0)
        {
            if (evictionType == EvictionType.LessRecentlyUsed && timeLimitInMilliseconds != 0)
            {
                throw new ArgumentException($"{nameof(timeLimitInMilliseconds)} can be used only for TTL eviction");
            }

            if (evictionType == EvictionType.TimeToLive && (limit != 0 || itemsToRemove != 0))
            {
                throw new ArgumentException($"{nameof(limit)} and {nameof(itemsToRemove)} can be used only for LRU eviction");
            }

            var request = new EvictionSetupRequest(fullTypeName, evictionType, limit, itemsToRemove, timeLimitInMilliseconds);

            var response = Channel.SendRequest(request);

            if (response is ExceptionResponse exResponse)
            {
                throw new CacheException("Error while declaring a domain", exResponse.Message, exResponse.CallStack);
            }
        }
コード例 #9
0
 public EvictionPolicyConfig(EvictionType type, int lruMaxItems, int lruEvictionCount)
 {
     Type             = type;
     LruMaxItems      = lruMaxItems;
     LruEvictionCount = lruEvictionCount;
 }