internal override CacheAddResult AddInternal(object key, CacheEntry cacheEntry, bool isUserOperation) { int bucketId = GetBucketId(key as string); if (_logMgr.IsOperationAllowed(bucketId) && LocalBuckets.Contains(bucketId)) { if (_logMgr.IsLoggingEnbaled(bucketId, LogMode.LogBeforeActualOperation) && isUserOperation) { _logMgr.LogOperation(bucketId, key, cacheEntry, OperationType.Add); return(CacheAddResult.Success); } CacheEntry clone = (CacheEntry)cacheEntry.Clone(); CacheAddResult result = base.AddInternal(key, cacheEntry, isUserOperation); if (result == CacheAddResult.Success || result == CacheAddResult.SuccessNearEviction) { IncrementBucketStats(key as string, bucketId, clone.DataSize); if (isUserOperation) { _logMgr.LogOperation(bucketId, key, clone, OperationType.Add); } } return(result); } throw new StateTransferException("I am no more the owner of this bucket"); }
internal override CacheEntry GetInternal(object key, bool isUserOperation, OperationContext operationContext) { CacheEntry entry = base.GetInternal(key, isUserOperation, operationContext); if (entry != null && operationContext != null && entry.ObjectType != null && operationContext.Contains(OperationContextFieldName.GenerateQueryInfo)) { CacheEntry clone = (CacheEntry)entry.Clone(); clone.QueryInfo = _queryIndexManager.GetQueryInfo(key, entry); return(clone); } return(entry); }
private async Task <bool> UpdateLastAccessedAsync(string key, CacheEntry storedEntry, IReliableDictionary <string, CacheEntry> dictionary, TimeSpan timeout, CancellationToken cancellationToken) { var newEntry = (CacheEntry)storedEntry.Clone(); newEntry.LastAccessed = DateTimeOffset.UtcNow; using (var transaction = _stateManager.CreateTransaction()) { var result = await dictionary.TryUpdateAsync(transaction, key, newEntry, storedEntry, timeout, cancellationToken); await transaction.CommitAsync(); return(result); } }
internal override CacheInsResult InsertInternal(object key, CacheEntry cacheEntry, bool isUserOperation, CacheEntry oldEntry, OperationContext operationContext) { int bucketId = GetBucketId(key as string); OperationLogger opLogger = null; //muds: //fetch the operation logger... if (_logMgr.IsOperationAllowed(bucketId) && LocalBuckets.Contains(bucketId)) { long oldEntrysize = oldEntry == null ? 0 : oldEntry.DataSize; if (_logMgr.IsLoggingEnbaled(bucketId, LogMode.LogBeforeActualOperation) && isUserOperation) { _logMgr.LogOperation(bucketId, key, cacheEntry, OperationType.Insert); return(oldEntry != null ? CacheInsResult.SuccessOverwrite : CacheInsResult.Success); } CacheEntry clone = (CacheEntry)cacheEntry.Clone(); CacheInsResult result = base.InsertInternal(key, cacheEntry, isUserOperation, oldEntry, operationContext); switch (result) { case CacheInsResult.SuccessNearEvicition: case CacheInsResult.Success: if (isUserOperation) { _logMgr.LogOperation(bucketId, key, clone, OperationType.Insert); } IncrementBucketStats(key as string, bucketId, cacheEntry.DataSize); break; case CacheInsResult.SuccessOverwriteNearEviction: case CacheInsResult.SuccessOverwrite: if (isUserOperation) { _logMgr.LogOperation(bucketId, key, clone, OperationType.Insert); } DecrementBucketStats(key as string, bucketId, oldEntrysize); IncrementBucketStats(key as string, bucketId, cacheEntry.DataSize); break; } return(result); } throw new StateTransferException("I am no more the owner of this bucket"); }
/// <summary> /// Get the cache entry to sync set /// </summary> /// <typeparam name="TValue"></typeparam> /// <param name="entry"></param> /// <returns></returns> protected CacheEntry <string, TValue> GetSyncSetCacheEntry <TValue>(CacheEntry <string, TValue> entry) { if (entry == null) { return(null); } var setEntry = entry.Clone(); var options = setEntry.Options; if (options.ExpirationMode == ExpirationMode.Absolute) { //calc new expiration timeout to make the entry timeout at the same time in all cache providers var newExpirationTimeout = options.CreatedUtc.Add(options.ExpirationTimeout) - DateTime.UtcNow; options.Timeout(newExpirationTimeout); } return(setEntry); }
public static EventCacheEntry CreateCacheEventEntry(EventDataFilter?filter, CacheEntry cacheEntry) { if (filter != EventDataFilter.None && cacheEntry != null) { cacheEntry = (CacheEntry)cacheEntry.Clone(); EventCacheEntry entry = new EventCacheEntry(cacheEntry); entry.Flags = cacheEntry.Flag; if (filter == EventDataFilter.DataWithMetadata) { if (cacheEntry.Value is CallbackEntry) { entry.Value = ((CallbackEntry)cacheEntry.Value).Value; } else { entry.Value = cacheEntry.Value; } } return(entry); } return(null); }
/// <summary> /// Adds a pair of key and value to the cache. If the specified key already exists /// in the cache; it is updated, otherwise a new item is added to the cache. /// </summary> /// <param name="key">key of the entry.</param> /// <param name="cacheEntry">the cache entry.</param> /// <returns>returns the result of operation.</returns> public override CacheInsResultWithEntry Insert(object key, CacheEntry cacheEntry, bool notify, object lockId, LockAccessType access, OperationContext operationContext) { bool requiresReplication = false; requiresReplication = _context.CacheImpl.RequiresReplication; if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.Insert_1", "enter"); Sync.AcquireWriterLock(Timeout.Infinite); try { CacheEntry clone = null; if (requiresReplication) { if (cacheEntry.HasQueryInfo) clone = cacheEntry.Clone() as CacheEntry; else clone = cacheEntry; } CacheInsResultWithEntry result = Internal.Insert(key, cacheEntry, notify, lockId, access, operationContext); if (requiresReplication) { if (result.Result == CacheInsResult.Success || result.Result == CacheInsResult.SuccessNearEvicition || result.Result == CacheInsResult.SuccessOverwrite || result.Result == CacheInsResult.SuccessOverwriteNearEviction) { CacheEntry cloneWithoutvalue = clone.CloneWithoutValue() as CacheEntry; if (result.Result == CacheInsResult.SuccessOverwrite && access == LockAccessType.DONT_RELEASE) { clone.CopyLock(result.Entry.LockId, result.Entry.LockDate, result.Entry.LockExpiration); } #if !CLIENT _context.CacheImpl.EnqueueForReplication(key, (int)ClusterCacheBase.OpCodes.Insert, new object[] { key, cloneWithoutvalue, operationContext }, clone.Size, cacheEntry.UserData, cacheEntry.DataSize); #endif } } return result; } finally { Sync.ReleaseWriterLock(); if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.Insert_1", "exit"); } }
/// <summary> /// Adds a pair of key and value to the cache. Throws an exception or reports error /// if the specified key already exists in the cache. /// </summary> /// <param name="key">key of the entry.</param> /// <param name="cacheEntry">the cache entry.</param> /// <param name="notify"></param> /// <param name="operationContext"></param> /// <returns>returns the result of operation.</returns> public override CacheAddResult Add(object key, CacheEntry cacheEntry, bool notify, OperationContext operationContext) { bool requiresReplication = _context.CacheImpl.RequiresReplication; if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.Add_1", "enter"); Sync.AcquireWriterLock(Timeout.Infinite); try { CacheEntry clone = null; if ((requiresReplication)) { if (cacheEntry.HasQueryInfo) clone = cacheEntry.Clone() as CacheEntry; else clone = cacheEntry; } CacheAddResult result = Internal.Add(key, cacheEntry, notify, operationContext); if (requiresReplication) { if (result == CacheAddResult.Success || result == CacheAddResult.SuccessNearEviction) { if (requiresReplication) { CacheEntry cloneWithoutvalue = clone.CloneWithoutValue() as CacheEntry; Array userPayLoad = cacheEntry.UserData; long payLoadSize = cacheEntry.DataSize; #if !CLIENT _context.CacheImpl.EnqueueForReplication(key, (int)ClusterCacheBase.OpCodes.Add, new object[] { key, cloneWithoutvalue, operationContext }, clone.Size, userPayLoad, payLoadSize); #endif } } } return result; } finally { Sync.ReleaseWriterLock(); if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.Add_1", "exit"); } }
internal override CacheInsResult InsertInternal(object key, CacheEntry cacheEntry, bool isUserOperation, CacheEntry oldEntry, OperationContext operationContext, bool updateIndex) { int bucketId = GetBucketId(key as string); OperationLogger opLogger = null; //muds: //fetch the operation logger... if (_logMgr.IsOperationAllowed(bucketId) && LocalBuckets.Contains(bucketId)) { long oldEntrysize = oldEntry == null ? 0 : oldEntry.DataSize; if (_logMgr.IsLoggingEnbaled(bucketId, LogMode.LogBeforeActualOperation) && isUserOperation) { _logMgr.LogOperation(bucketId, key, cacheEntry, OperationType.Insert); return oldEntry != null ? CacheInsResult.SuccessOverwrite : CacheInsResult.Success; } CacheEntry clone = (CacheEntry)cacheEntry.Clone(); CacheInsResult result = base.InsertInternal(key, cacheEntry, isUserOperation, oldEntry, operationContext, updateIndex); switch (result) { case CacheInsResult.SuccessNearEvicition: case CacheInsResult.Success: if (isUserOperation) _logMgr.LogOperation(bucketId, key, clone, OperationType.Insert); IncrementBucketStats(key as string, bucketId, cacheEntry.DataSize); break; case CacheInsResult.SuccessOverwriteNearEviction: case CacheInsResult.SuccessOverwrite: if (isUserOperation) _logMgr.LogOperation(bucketId, key, clone, OperationType.Insert); DecrementBucketStats(key as string, bucketId, oldEntrysize); IncrementBucketStats(key as string, bucketId, cacheEntry.DataSize); break; } return result; } throw new StateTransferException("I am no more the owner of this bucket"); }
internal override CacheAddResult AddInternal(object key, CacheEntry cacheEntry, bool isUserOperation, OperationContext operationContext) { int bucketId = GetBucketId(key as string); if (_logMgr.IsOperationAllowed(bucketId) && LocalBuckets.Contains(bucketId)) { if (_logMgr.IsLoggingEnbaled(bucketId, LogMode.LogBeforeActualOperation) && isUserOperation) { _logMgr.LogOperation(bucketId, key, cacheEntry, OperationType.Add); return CacheAddResult.Success; } CacheEntry clone = (CacheEntry)cacheEntry.Clone(); CacheAddResult result = base.AddInternal(key, cacheEntry, isUserOperation, operationContext); if (result == CacheAddResult.Success || result == CacheAddResult.SuccessNearEviction) { IncrementBucketStats(key as string, bucketId, clone.DataSize); if (isUserOperation) _logMgr.LogOperation(bucketId, key, clone, OperationType.Add); } return result; } throw new StateTransferException("I am no more the owner of this bucket"); }