public InsertCommand(string key, byte[] value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short removeCallback, short updateCallback, Hashtable queryInfo, BitSet flagMap, object lockId, LockAccessType accessType, string cacheId, EventDataFilter updateCallbackFilter, EventDataFilter removeCallabackFilter) { base.name = "InsertCommand"; base.key = key; _insertCommand = new Alachisoft.NCache.Common.Protobuf.InsertCommand(); _insertCommand.key = key; Alachisoft.NCache.Caching.UserBinaryObject ubObject = UserBinaryObject.CreateUserBinaryObject(value); _insertCommand.data.AddRange(ubObject.DataList); _insertCommand.requestId = base.RequestId; _insertCommand.removeCallbackId = removeCallback; _insertCommand.updateCallbackId = updateCallback; _insertCommand.updateDataFilter = (short)updateCallbackFilter; _insertCommand.removeDataFilter = (short)removeCallabackFilter; _insertCommand.priority = (int)priority; _insertCommand.flag = flagMap.Data; if(lockId != null) _insertCommand.lockId = lockId.ToString(); _insertCommand.lockAccessType = (int)accessType; if (absoluteExpiration != Web.Caching.Cache.NoAbsoluteExpiration) _insertCommand.absExpiration = absoluteExpiration.Ticks; if (slidingExpiration != Web.Caching.Cache.NoSlidingExpiration) _insertCommand.sldExpiration = slidingExpiration.Ticks; ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo(); if (queryInfo["query-info"] != null) objectQueryInfo.queryInfo = ProtobufHelper.GetQueryInfoObj(queryInfo["query-info"] as Hashtable); _insertCommand.objectQueryInfo = objectQueryInfo; }
internal AddCommand(string key, byte[] value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short removeCallback, short updateCallback, Hashtable queryInfo, BitSet flagMap, string cacheId,EventDataFilter updateDataFilter,EventDataFilter removeDataFilter) { base.name = "AddCommand"; base.key = key; _addCommand = new Alachisoft.NCache.Common.Protobuf.AddCommand(); if (absoluteExpiration != Cache.NoAbsoluteExpiration) _addCommand.absExpiration = absoluteExpiration.Ticks; if (slidingExpiration != Cache.NoSlidingExpiration) _addCommand.sldExpiration = slidingExpiration.Ticks; Alachisoft.NCache.Caching.UserBinaryObject ubObject = Alachisoft.NCache.Caching.UserBinaryObject.CreateUserBinaryObject(value); _addCommand.key = key; _addCommand.data.AddRange(ubObject.DataList); _addCommand.requestId = base.RequestId; _addCommand.updateCallbackId = updateCallback; _addCommand.removeCallbackId = removeCallback; _addCommand.priority = (int)priority; _addCommand.flag = flagMap.Data; _addCommand.updateDataFilter = (short)updateDataFilter; _addCommand.removeDataFilter = (short)removeDataFilter; // Changes made to send Queries, Tags and NamgedTags in a single object ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo(); if (queryInfo["query-info"] != null) objectQueryInfo.queryInfo = ProtobufHelper.GetQueryInfoObj(queryInfo["query-info"] as Hashtable); _addCommand.objectQueryInfo = objectQueryInfo; }
internal static ItemRemoveCallbackResponse GetItemRemovedCallbackResponse(EventContext eventContext, short id, string key, UserBinaryObject value, BitSet flag, ItemRemoveReason reason,EventDataFilter dataFilter) { Alachisoft.NCache.Common.Protobuf.ItemRemoveCallbackResponse itemRemovedCallback = new Alachisoft.NCache.Common.Protobuf.ItemRemoveCallbackResponse(); itemRemovedCallback.key = key; itemRemovedCallback.callbackId = id; itemRemovedCallback.itemRemoveReason = (int)reason; itemRemovedCallback.flag = flag != null? (int)flag.Data : 0; itemRemovedCallback.dataFilter = (short)dataFilter; itemRemovedCallback.eventId = new Common.Protobuf.EventId(); UserBinaryObject binaryObject = eventContext.Item != null ?(UserBinaryObject) eventContext.Item.Value : null; if(binaryObject != null) itemRemovedCallback.value.AddRange(binaryObject.DataList); if (eventContext != null) { itemRemovedCallback.eventId.eventUniqueId = eventContext.EventID.EventUniqueID; itemRemovedCallback.eventId.operationCounter = eventContext.EventID.OperationCounter; itemRemovedCallback.eventId.eventCounter = eventContext.EventID.EventCounter; if (eventContext.Item != null) itemRemovedCallback.flag = eventContext.Item.Flags.Data; itemRemovedCallback.eventId.item = ConvertToEventItem(eventContext.Item, null); if (itemRemovedCallback.eventId.item != null && itemRemovedCallback.eventId.item.value != null) { itemRemovedCallback.eventId.item.value.Clear();//data will be travalling in old fashion due to old callbacks } } return itemRemovedCallback; }
internal ClearCommand(BitSet flagMap) { base.name = "ClearCommand"; _clearCommand = new Alachisoft.NCache.Common.Protobuf.ClearCommand(); _clearCommand.flag = flagMap.Data; _clearCommand.requestId = base.RequestId; }
public BulkGetCommand(string[] keys, BitSet flagMap) { base.name = "BulkGetCommand"; base.BulkKeys = keys; _bulkGetCommand = new Alachisoft.NCache.Common.Protobuf.BulkGetCommand(); _bulkGetCommand.keys.AddRange(keys); _bulkGetCommand.flag = flagMap.Data; _bulkGetCommand.requestId = base.RequestId; }
public ItemUpdateCallbackTask(Broker parent, string key, short callBackId, bool notifyAsync, EventCacheItem item, EventCacheItem oldItem, BitSet flag,EventDataFilter dataFilter) { this._parent = parent; this._key = key; this._callBackId = callBackId; this._notifyAsync = notifyAsync; this._item = item; this._oldItem = oldItem; this._flag = flag; this._dataFilter = dataFilter; }
internal ItemRemoveCallback(short id, string key, object value, ItemRemoveReason reason, string clientId, BitSet Flag, EventContext eventContext,EventDataFilter dataFilter) { _id = id; _key = key; _value = value as UserBinaryObject; _flag = Flag; _reason = reason; _clientID = clientId; _eventContext = eventContext; _dataFilter = dataFilter; }
public ItemRemoveCallBackTask(Broker parent, string key, short callBackId, object value, CacheItemRemovedReason reason, BitSet flag, bool notifyAsync, EventCacheItem item,EventDataFilter dataFilter) { this._parent = parent; this._key = key; this._callBackId = callBackId; this._value = value; this._reason = reason; this._flag = flag; this._notifyAsync = notifyAsync; this._item = item; this._dataFilter = dataFilter; }
/// <summary> /// Creates a CallBackEntry. /// </summary> /// <param name="clientid"></param> /// <param name="reqId"></param> /// <param name="value">Actual data</param> /// <param name="onCacheItemRemovedCallback">OnCacheItemRemovedCallback</param> /// <param name="onCacheItemUpdateCallback">OnCacheItemUpdateCallback</param> /// <param name="Flag"></param> /// <param name="updateDatafilter"></param> /// <param name="removeDatafilter"></param> /// <param name="callerid">Caller id i.e. Clietn application id</param> public CallbackEntry(string clientid, int reqId, object value, short onCacheItemRemovedCallback, short onCacheItemUpdateCallback, BitSet Flag, EventDataFilter updateDatafilter, EventDataFilter removeDatafilter) { _value = value; _flag = Flag; if (onCacheItemUpdateCallback != -1) { _itemUpdateListener.Add(new CallbackInfo(clientid, onCacheItemUpdateCallback, updateDatafilter)); } if (onCacheItemRemovedCallback != -1) { _itemRemovedListener.Add(new CallbackInfo(clientid, onCacheItemRemovedCallback, removeDatafilter)); } }
public DeleteCommand(string key, BitSet flagMap, object lockId, LockAccessType accessType) { base.name = "DeleteCommand"; base.key = key; _deleteCommand = new Alachisoft.NCache.Common.Protobuf.DeleteCommand(); _deleteCommand.key = key; flagMap.SetBit(BitSetConstants.LockedItem); _deleteCommand.flag = flagMap.Data; if (lockId != null) _deleteCommand.lockId = lockId.ToString(); _deleteCommand.lockAccessType = (int)accessType; _deleteCommand.requestId = base.RequestId; }
public CompactCacheEntry(object key, object value, ExpirationHint dependency, long expiration, byte options, object itemRemovedCallback, Hashtable queryInfo, BitSet Flag, object lockId, LockAccessType accessType) { _key = key; _flag = Flag; _value = value; _dependency = dependency; _expiration = expiration; _options = options; _itemRemovedCallback = itemRemovedCallback; _queryInfo = queryInfo; _lockId = lockId; _accessType = accessType; }
public GetCacheItemCommand(string key, BitSet flagMap, LockAccessType accessType, object lockId, TimeSpan lockTimeout) { base.name = "GetCacheItemCommand"; base.key = key; _getCacheItemCommand = new Alachisoft.NCache.Common.Protobuf.GetCacheItemCommand(); _getCacheItemCommand.key = key; _getCacheItemCommand.requestId = base.RequestId; _getCacheItemCommand.flag = flagMap.Data; _getCacheItemCommand.lockInfo = new Alachisoft.NCache.Common.Protobuf.LockInfo(); _getCacheItemCommand.lockInfo.lockAccessType = (int)accessType; if (lockId != null) _getCacheItemCommand.lockInfo.lockId = lockId.ToString(); _getCacheItemCommand.lockInfo.lockTimeout = lockTimeout.Ticks; }
/// <summary> /// Copy constructor /// </summary> /// <param name="info"></param> protected NodeInfo(NodeInfo info) { this._address = info._address == null ? null : info._address.Clone() as Address; this._rendererAddress = info._rendererAddress != null ? info._rendererAddress.Clone() as Address : null; this._stats = info._stats == null ? null:info._stats.Clone() as CacheStatistics; this._status = info._status; this._subgroupName = info._subgroupName; this._isInproc = info._isInproc; this._dataAffinity = info._dataAffinity == null ? null : info._dataAffinity.Clone() as DataAffinity; _isStartedAsMirror = info.IsStartedAsMirror; if(info._connectedClients != null) { lock(info._connectedClients.SyncRoot) this._connectedClients = info._connectedClients.Clone() as ArrayList; } }
/// <summary> Insert list of <see cref="CacheItem"/> to the cache </summary> /// <param name="keys">The cache keys used to reference the items.</param> /// <param name="items">The items that are to be stored</param> /// <param name="sizes"></param> /// <param name="allowQueryTags"></param> /// <returns>returns keys that are added or updated successfully and their status.</returns> /// <remarks> If CacheItem contains invalid values the related exception is thrown. /// See <see cref="CacheItem"/> for invalid property values and related exceptions</remarks> /// <example>The following example demonstrates how to assign an item high priority when you insert /// it into your application's <see cref="Cache"/> object. /// <para><b>Note: </b>For more information about how to use this method with the <see cref="CacheItemRemovedCallback"/> /// delegate, see <see cref="CacheItemRemovedCallback"/>. /// </para> /// First create CacheItems. /// <code> /// string[] keys = {"SQLDSN", "ORADSN"}; /// CacheItem items[] = new CacheItem[2]; /// items[0] = new CacheItem(sqlConnectionString); /// item.AbsoluteExpiration = DateTime.Now.AddMinutes(2); /// item.Priority = CacheItemPriority.High; /// item.ItemRemoveCallback = onRemove; /// /// items[1] = new CacheItem(oraConnectionString); /// item.AbsoluteExpiration = DateTime.Now.AddMinutes(1); /// item.Priority = CacheItemPriority.Low; /// item.ItemRemoveCallback = onRemove; /// </code> /// /// Then insert CacheItems to the cache /// <code> /// Cache cache = NCache.InitializeCache("myCache"); /// string[] keys = new string[] { "myItem1", "myItem2" }; /// CacheItem[] items = new CacheItem[]{myItem1, myItem2}; /// cache.Insert(keys, items, "Connection", null); /// /// </code> /// </example> internal virtual IDictionary InsertBulkOperation(string[] keys, CacheItem[] items, ref long[] sizes, bool allowQueryTags) { if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized"); if (keys == null) throw new ArgumentNullException("keys"); if (items == null) throw new ArgumentNullException("items"); if (keys.Length != items.Length) throw new ArgumentException("keys count is not equals to items count"); if (keys.Length == 0) throw new ArgumentException("There is no key present in keys array"); if (IsNullOrDupliate(keys)) throw new ArgumentException("Duplicate keys found in provided 'key' array."); CacheItem[] clonedItems = new CacheItem[items.Length]; int noOfObjects = 0; long sumObjectSize = 0; if (DebugAPIConfiguraions.LoggingEnabled) noOfObjects = items.Length; for (int i = 0; i < items.Length; i++) { string key = keys[i]; BitSet flagMap = new BitSet(); if (items[i] == null) throw new Exception("CacheItem cannot be null"); CacheItem cloned = items[i].Clone() as CacheItem; long size = 0; if (sizes[i] > 0) size = sizes[i]; ValidateKeyValue(key, cloned.Value); Hashtable queryInfo = new Hashtable(); if (allowQueryTags) { queryInfo["query-info"] = GetQueryInfo(cloned.Value); } cloned.QueryInfo = queryInfo; cloned.Value = SafeSerialize(cloned.Value, _serializationContext, ref flagMap, ref size); sizes[i] = size; if (DebugAPIConfiguraions.LoggingEnabled) sumObjectSize += cloned.Value is byte[] ? ((byte[])cloned.Value).Length : 0; if (_perfStatsCollector != null) { if (cloned.Value != null) _perfStatsCollector.IncrementAvgItemSize(((byte[])cloned.Value).Length); } cloned.FlagMap = flagMap; cloned.AbsoluteExpiration = ToUTC(cloned.AbsoluteExpiration); clonedItems[i] = cloned; } if (DebugAPIConfiguraions.LoggingEnabled) LogSizeInfo(true, sumObjectSize, noOfObjects); short dsItemAddedCallbackID = -1; try { return _cacheImpl.Insert(keys, clonedItems, sizes); } catch (Exception) { if (ExceptionsEnabled) throw; return null; } }
internal virtual object GetInternal(string key, LockAccessType accessType, TimeSpan lockTimeout, ref LockHandle lockHandle) { if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized"); if (key == null) throw new ArgumentNullException("key"); if (key == string.Empty) throw new ArgumentException("key cannot be empty string"); long objectSize = 0; CompressedValueEntry result = null; try { BitSet flagMap = new BitSet(); UsageStats stats = new UsageStats(); stats.BeginSample(); result = _cacheImpl.Get(key, flagMap, ref lockHandle, lockTimeout, accessType); if (_perfStatsCollector != null) { stats.EndSample(); _perfStatsCollector.IncrementMsecPerGetSample(stats.Current); _perfStatsCollector.IncrementGetPerSecStats(); } if (result != null && result.Value != null) { if (result.Value is CallbackEntry) { CallbackEntry e = result.Value as CallbackEntry; result.Value = e.Value; } if (DebugAPIConfiguraions.LoggingEnabled) objectSize = result.Value is byte[] ? ((byte[])result.Value).Length : 0; result.Value = SafeDeserialize(result.Value, _serializationContext, result.Flag); if (DebugAPIConfiguraions.LoggingEnabled) LogSizeInfo(false, objectSize); return result.Value; } } catch (Exception) { if (ExceptionsEnabled) throw; else return null; } return null; }
internal virtual CacheItem GetCacheItemInternal(string key, LockAccessType accessType, TimeSpan lockTimeout, ref LockHandle lockHandle) { if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized"); if (key == null) throw new ArgumentNullException("keys"); if (key == string.Empty) throw new ArgumentException("key cannot be empty string"); try { CacheItem item = new CacheItem(); Alachisoft.NCache.Caching.CacheEntry entry = null; BitSet flagMap = new BitSet(); object value = _cacheImpl.GetCacheItem(key, flagMap, ref lockHandle, lockTimeout, accessType); long objectSize = 0; if (value == null) return null; if (value is CacheItem) { item = (CacheItem)value; if (_perfStatsCollector != null && ((CacheItem)value).Value != null && ((CacheItem)value).Value is byte[]) _perfStatsCollector.IncrementAvgItemSize(((byte[])((CacheItem)value).Value).Length); if (DebugAPIConfiguraions.LoggingEnabled) objectSize = ((byte[])item.Value).Length; item.Value = SafeDeserialize(item.Value, _serializationContext, item.FlagMap); if (item.AbsoluteExpiration != Cache.NoAbsoluteExpiration) { item.AbsoluteExpiration = item.AbsoluteExpiration.ToLocalTime(); } if (DebugAPIConfiguraions.LoggingEnabled) LogSizeInfo(false, objectSize); return item; } entry = (Alachisoft.NCache.Caching.CacheEntry)value; item.FlagMap = entry.Flag; if (entry.Value is CallbackEntry) { CallbackEntry cb = (CallbackEntry)entry.Value; if (cb.ItemRemoveCallbackListener != null && cb.ItemRemoveCallbackListener.Count > 0) { foreach (CallbackInfo cbInfo in cb.ItemRemoveCallbackListener) { if (cbInfo.Client == _cacheImpl.ClientID) { item.SetCacheDataNotification((CacheDataNotificationCallback)_callbackIDsMap.GetResource(cbInfo.Callback), EventType.ItemRemoved); break; } } } if (cb.ItemUpdateCallbackListener != null && cb.ItemUpdateCallbackListener.Count > 0) { foreach (CallbackInfo cbInfo in cb.ItemUpdateCallbackListener) { if (cbInfo.Client == _cacheImpl.ClientID) { item.SetCacheDataNotification((CacheDataNotificationCallback)_callbackIDsMap.GetResource(cbInfo.Callback), EventType.ItemUpdated); break; } } } item.Value = cb.Value; if (_perfStatsCollector != null && item.Value != null && item.Value is byte[]) _perfStatsCollector.IncrementAvgItemSize(((byte[])item.Value).Length); item.Value = SafeDeserialize(cb.Value, _serializationContext, item.FlagMap); } else { item.Value = entry.Value; if (_perfStatsCollector != null && item.Value != null && item.Value is byte[]) _perfStatsCollector.IncrementAvgItemSize(((byte[])item.Value).Length); if (DebugAPIConfiguraions.LoggingEnabled) objectSize = ((byte[])entry.Value).Length; item.Value = SafeDeserialize(entry.Value, _serializationContext, item.FlagMap); } if (DebugAPIConfiguraions.LoggingEnabled) LogSizeInfo(false, objectSize); if (entry != null) { item.Priority = (CacheItemPriority)entry.Priority; } ExpirationHint hint = entry.ExpirationHint; DateTime absoluteExpiration = DateTime.MaxValue.ToUniversalTime(); TimeSpan slidingExpiration = TimeSpan.Zero; Alachisoft.NCache.Caching.AutoExpiration.DependencyHelper.GetActualCacheDependency(hint, ref absoluteExpiration, ref slidingExpiration); if (absoluteExpiration != Cache.NoAbsoluteExpiration) { item.AbsoluteExpiration = absoluteExpiration.ToLocalTime(); } item.SlidingExpiration = slidingExpiration; item._creationTime = entry.CreationTime; item._lastModifiedTime = entry.LastModifiedTime; return item; } catch (Exception) { if (ExceptionsEnabled) throw; } return null; }
internal virtual void Delete(string key, LockHandle lockHandle, LockAccessType accessType) { if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized"); if (key == null) throw new ArgumentNullException("key"); if (key == string.Empty) throw new ArgumentException("key cannot be empty string"); try { UsageStats stats = new UsageStats(); stats.BeginSample(); object lockId = (lockHandle == null) ? null : lockHandle.LockId; BitSet flagMap = new BitSet(); _cacheImpl.Delete(key, flagMap, lockId, accessType); } catch (Exception) { if (ExceptionsEnabled) throw; } }
public void Deserialize(Runtime.Serialization.IO.CompactReader reader) { Priority = reader.ReadInt32(); Flags = new BitSet(reader.ReadByte()); Value = reader.ReadObject(); }
/// <summary> /// Function that choose the appropriate function of NCache's Cache, that need to be called /// according to the data provided to it.</summary> internal virtual void InsertOperation(string key, object value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, LockHandle lockHandle, LockAccessType accessType, CacheDataNotificationCallback cacheItemUdpatedCallback, CacheDataNotificationCallback cacheItemRemovedCallaback, EventDataFilter itemUpdateDataFilter, EventDataFilter itemRemovedDataFilter, ref long size, bool allowQueryTags) { if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized"); ValidateKeyValue(key, value); UsageStats stats = new UsageStats(); stats.BeginSample(); Hashtable queryInfo = new Hashtable(); object lockId = (lockHandle == null) ? null : lockHandle.LockId; if (allowQueryTags) { queryInfo["query-info"] = GetQueryInfo(value); } short removeCallbackId = -1; short updateCallbackId = -1; short dsItemUpdateCallbackId = -1; BitSet flagMap = new BitSet(); try { value = SafeSerialize(value, _serializationContext, ref flagMap, ref size); long objectSize = 0; if (DebugAPIConfiguraions.LoggingEnabled) objectSize = value is byte[] ? ((byte[])value).Length : 0; if (_perfStatsCollector != null && value != null && value is byte[]) _perfStatsCollector.IncrementAvgItemSize(((byte[])value).Length); if (cacheItemRemovedCallaback != null) { short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemRemovedCallaback, EventType.ItemRemoved, itemRemovedDataFilter); removeCallbackId = callabackIds[1]; } if (cacheItemUdpatedCallback != null) { short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemUdpatedCallback, EventType.ItemUpdated, itemUpdateDataFilter); updateCallbackId = callabackIds[0]; } if (lockId != null && ((string)lockId) != string.Empty) flagMap.SetBit(BitSetConstants.LockedItem); else flagMap.UnsetBit(BitSetConstants.LockedItem); absoluteExpiration = ToUTC(absoluteExpiration); _cacheImpl.Insert(key, value, absoluteExpiration, slidingExpiration, priority, removeCallbackId, updateCallbackId, queryInfo, flagMap, lockId, accessType, itemUpdateDataFilter, itemRemovedDataFilter, size); if (_perfStatsCollector != null) { stats.EndSample(); _perfStatsCollector.IncrementMsecPerUpdSample(stats.Current); _perfStatsCollector.IncrementUpdPerSecStats(); } } catch (Exception) { if (ExceptionsEnabled) throw; } }
internal virtual object SafeSerialize(object serializableObject, string serializationContext, ref BitSet flag, ref long size) { object serializedObject = null; if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized"); if (serializableObject != null) { UsageStats statsSerialization = new UsageStats(); statsSerialization.BeginSample(); serializedObject = _cacheImpl.SafeSerialize(serializableObject, serializationContext, ref flag, _cacheImpl, ref size); statsSerialization.EndSample(); if (_perfStatsCollector != null) _perfStatsCollector.IncrementMsecPerSerialization(statsSerialization.Current); } return serializedObject; }
internal virtual object Remove(string key, LockHandle lockHandle, LockAccessType accessType) { if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized"); if (key == null) throw new ArgumentNullException("key"); if (key == string.Empty) throw new ArgumentException("key cannot be empty string"); long objectSize = 0; try { UsageStats stats = new UsageStats(); stats.BeginSample(); object lockId = (lockHandle == null) ? null : lockHandle.LockId; BitSet flagMap = new BitSet(); short dsItemRemovedCallbackId = -1; CompressedValueEntry result = _cacheImpl.Remove(key, flagMap, lockId, accessType); if (result != null && result.Value != null) { if (result.Value != null && result.Value is CallbackEntry) { result.Value = ((CallbackEntry)result.Value).Value; } if (DebugAPIConfiguraions.LoggingEnabled) objectSize = result.Value is byte[] ? ((byte[])result.Value).Length : 0; result.Value = SafeDeserialize(result.Value, _serializationContext, result.Flag); if (_perfStatsCollector != null) { stats.EndSample(); _perfStatsCollector.IncrementMsecPerDelSample(stats.Current); _perfStatsCollector.IncrementDelPerSecStats(); } if (DebugAPIConfiguraions.LoggingEnabled) LogSizeInfo(false, objectSize); return result.Value; } else { if (_perfStatsCollector != null) { stats.EndSample(); _perfStatsCollector.IncrementMsecPerDelSample(stats.Current); _perfStatsCollector.IncrementDelPerSecStats(); } } } catch (Exception) { if (ExceptionsEnabled) throw; } return null; }
public virtual void OnCustomUpdateCallback(string key, object value, bool notifyAsync, EventCacheItem item, EventCacheItem oldItem, BitSet flag) { try { CallbackInfo cbInfo = value as CallbackInfo; if (cbInfo != null) { if (item != null) item.Value = GetObject(item.Value, flag); if (oldItem != null) oldItem.Value = GetObject(oldItem.Value, flag); if (_parent._perfStatsCollector != null) _parent._perfStatsCollector.IncrementEventsProcessedPerSec(); EventHandle handle = new EventHandle((short) cbInfo.Callback); this._eventManager.RaiseSelectiveCacheNotification(key, EventType.ItemUpdated, item, oldItem, CacheItemRemovedReason.Underused, notifyAsync, handle, cbInfo.DataFilter); } } catch { } }
public virtual void OnCustomRemoveCallback(string key, object value, CacheItemRemovedReason reason, BitSet flag, bool notifyAsync, EventCacheItem item) { try { object[] args = value as object[]; if (args != null) { object val = args[0]; CallbackInfo cbInfo = args[1] as CallbackInfo; if (cbInfo != null) { if (_parent._perfStatsCollector != null) _parent._perfStatsCollector.IncrementEventsProcessedPerSec(); if (item != null) item.Value = GetObject(item.Value, flag); EventHandle handle = new EventHandle((short)cbInfo.Callback); _parent.EventManager.RaiseSelectiveCacheNotification(key, EventType.ItemRemoved, item, null, reason, notifyAsync, handle, cbInfo.DataFilter); } } } catch { } }
/// <summary> /// Removes the objects from the <see cref="Cache"/>. /// </summary> /// <param name="keys">The cache keys used to reference the item.</param> /// <exception cref="ArgumentNullException"><paramref name="keys"/> contains a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentException"><paramref name="keys"/> is not serializable.</exception> /// <remarks> /// <para><b>Note:</b> If exceptions are enabled through the <see cref="ExceptionsEnabled"/> /// setting, this property throws exception incase of failure.</para> /// </remarks> /// <example>The following example demonstrates how you can remove an item from your application's /// <see cref="Cache"/> object. /// <code> /// Cache cache = NCache.InitializeCache("myCache"); /// string[] keys = new string[]{"myItem1", "myItem2"}; /// cache.DeleteBulk(keys); /// /// </code> /// </example> /// public virtual void DeleteBulk(string[] keys) { if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized"); if (keys == null) throw new ArgumentNullException("keys"); if (keys.Length == 0) throw new ArgumentException("There is no key present in keys array"); IsNullOrDupliate(keys); try { BitSet flagMap = new BitSet(); _cacheImpl.Delete(keys, flagMap); } catch (Exception) { if (ExceptionsEnabled) throw; } }
private object GetObject(object value, BitSet Flag) { try { if (value is CallbackEntry) { value = ((CallbackEntry)value).Value; } if (value is UserBinaryObject) value = ((UserBinaryObject)value).GetFullObject(); return _parent.SafeDeserialize(value, _parent._serializationContext, Flag); } catch (Exception ex) { return value; } }
public static object SafeSerialize(object serializableObject, string serializationContext, ref BitSet flag) { if (serializableObject != null) { if (serializableObject is byte[]) { flag.SetBit(BitSetConstants.BinaryData); return serializableObject; } serializableObject = CompactBinaryFormatter.ToByteBuffer(serializableObject, serializationContext); } return serializableObject; }
/// <summary> /// Retrieves the object from the cache for the given keys as key value pairs /// </summary> /// <param name="keys">The keys against which items are to be fetched.</param> /// <returns>The retrieved cache items.</returns> /// <exception cref="ArgumentNullException"><paramref name="keys"/> contains a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentException"><paramref name="keys"/> is not serializable.</exception> /// <remarks> /// <para><b>Note:</b> If exceptions are enabled through the <see cref="ExceptionsEnabled"/> /// setting, this property throws exception incase of failure.</para> /// </remarks> /// <example>The following example demonstrates how to retrieve the value cached for an ASP.NET text /// box server control. /// <code> /// Cache cache = NCache.InitializeCache("myCache"); /// string[] keys = new string[]{"myItem1", "myItem2"}; /// IDictionary items = cache.Get(keys); /// /// </code> /// </example> public virtual IDictionary GetBulk(string[] keys) { if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized"); if (keys == null) throw new ArgumentNullException("keys"); if (keys.Length == 0) throw new ArgumentException("There is no key present in keys array"); RemoveDuplicateKeys(ref keys); try { BitSet flagMap = new BitSet(); IDictionary table = (IDictionary)_cacheImpl.Get(keys, flagMap); long sumObjectSize = 0; int noOfObjects = 0; if (table != null) { if (DebugAPIConfiguraions.LoggingEnabled) noOfObjects = table.Count; object[] keyArr = new object[table.Count]; table.Keys.CopyTo(keyArr, 0); IEnumerator ie = keyArr.GetEnumerator(); while (ie.MoveNext()) { CompressedValueEntry result = table[ie.Current] as CompressedValueEntry; if (result != null) { if (result.Value is CallbackEntry) { CallbackEntry e = result.Value as CallbackEntry; result.Value = e.Value; } if (_perfStatsCollector != null && result.Value != null && result.Value is byte[]) _perfStatsCollector.IncrementAvgItemSize(((byte[])result.Value).Length); if (DebugAPIConfiguraions.LoggingEnabled) sumObjectSize += result.Value is byte[] ? ((byte[])result.Value).Length : 0; table[ie.Current] = SafeDeserialize(result.Value, _serializationContext, result.Flag); } } } if (DebugAPIConfiguraions.LoggingEnabled) LogSizeInfo(true, sumObjectSize, noOfObjects); return table; } catch (Exception) { if (ExceptionsEnabled) throw; } return null; }
public static object SafeDeserialize(object serializedObject, string serializationContext, BitSet flag) { object deserialized = serializedObject; try { if(!flag.IsBitSet(BitSetConstants.BinaryData)) { if (serializedObject is byte[]) { deserialized = CompactBinaryFormatter.FromByteBuffer((byte[])serializedObject, serializationContext); } else if (serializedObject is UserBinaryObject) { deserialized = CompactBinaryFormatter.FromByteBuffer(((UserBinaryObject)serializedObject).GetFullObject(), serializationContext); } } } catch (Exception ex) { //Kill the exception; it is possible that object was serialized by Java //or from any other domain which can not be deserialized by us. deserialized = serializedObject; } return deserialized; }
void ICompactSerializable.Deserialize(CompactReader reader) { lock (this) { Value = reader.ReadObject(); _bitset = new BitSet(reader.ReadByte()); _evh = EvictionHint.ReadEvcHint(reader); _exh = ExpirationHint.ReadExpHint(reader); _queryInfo = (Hashtable)reader.ReadObject(); _size = reader.ReadInt64(); lockMetaInfo = reader.ReadObject() as LockMetaInfo; _creationTime = reader.ReadDateTime(); _lastModifiedTime = reader.ReadDateTime(); _priorityValue = (CacheItemPriority)reader.ReadInt32(); _type = reader.ReadObject() as string; } }
/// <summary> /// Function that choose the appropriate function of NCache's Cache, that need to be called /// according to the data provided to it.</summary> internal virtual object AddOperation(string key, object value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheDataNotificationCallback cacheItemUdpatedCallback, CacheDataNotificationCallback cacheItemRemovedCallaback, EventDataFilter itemUpdateDataFilter, EventDataFilter itemRemovedDataFilter, ref long size, bool allowQueryTags) { if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized"); ValidateKeyValue(key, value); UsageStats stats = new UsageStats(); stats.BeginSample(); Hashtable queryInfo = new Hashtable(); if (allowQueryTags) { queryInfo["query-info"] = GetQueryInfo(value); } BitSet flagMap = new BitSet(); try { long objectSize = 0; value = SafeSerialize(value, _serializationContext, ref flagMap, ref size); if (DebugAPIConfiguraions.LoggingEnabled) objectSize = value is byte[] ? ((byte[])value).Length : 0; if (_perfStatsCollector != null && value != null && value is byte[]) _perfStatsCollector.IncrementAvgItemSize(((byte[])value).Length); if (DebugAPIConfiguraions.LoggingEnabled) { LogSizeInfo(false, objectSize); } short removeCallbackID = -1; short updateCallbackID = -1; if (cacheItemRemovedCallaback != null) { short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemRemovedCallaback, EventType.ItemRemoved, itemRemovedDataFilter); removeCallbackID = callabackIds[1]; } if (cacheItemUdpatedCallback != null) { short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemUdpatedCallback, EventType.ItemUpdated, itemUpdateDataFilter); updateCallbackID = callabackIds[0]; } absoluteExpiration = ToUTC(absoluteExpiration); _cacheImpl.Add(key, value, absoluteExpiration, slidingExpiration, priority, removeCallbackID, updateCallbackID, queryInfo, flagMap, itemUpdateDataFilter, itemRemovedDataFilter, size); if (_perfStatsCollector != null) { stats.EndSample(); _perfStatsCollector.IncrementMsecPerAddSample(stats.Current); _perfStatsCollector.IncrementAddPerSecStats(); } return value; } catch (Exception) { if (ExceptionsEnabled) throw; } return null; }