/// <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; }
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); }
/// <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; }
/// <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); }
/// <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); }
/// <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); } }
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; } } }
/// <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); } }
public EvictionPolicyConfig(EvictionType type, int lruMaxItems, int lruEvictionCount) { Type = type; LruMaxItems = lruMaxItems; LruEvictionCount = lruEvictionCount; }