public override void Add(T item) { IRedisCachedObject castedItem = GetCastedItem(item); // TODO: this needs to add to the locally stored value as well Service.Cache(castedItem.Id, item); }
/// <summary> /// Removes an item from the collection /// </summary> /// <param name="item">The item to remove</param> /// <param name="throwException">If an exception should be thrown when the item can not be cached</param> /// <exception cref="System.InvalidOperationException">Unable to cast the item to a /// <see cref="StandardDot.Caching.Redis.Abstract.IRedisCachedObject" /></exception> /// <returns>If the item was removed</returns> protected virtual IRedisCachedObject GetCastedItem(T item, bool throwException = true) { IRedisCachedObject castedItem = item as IRedisCachedObject; if (throwException && castedItem == null) { throw new InvalidOperationException("Cannot add an item that doesn't derive from IRedisCachedObject"); } return(castedItem); }
/// <summary> /// Removes an item from redis /// </summary> /// <param name="item">The item to remove</param> /// <returns>If the item was removed</returns> public override bool Remove(T item) { IRedisCachedObject castedItem = GetCastedItem(item, false); if (string.IsNullOrWhiteSpace(castedItem?.Id?.ObjectIdentifier)) { return(false); } Source = Source.Cast <IRedisCachedObject>().Where(x => x.Id.FullKey != castedItem.Id.FullKey).Cast <T>(); return(Service.Invalidate(castedItem.Id)); }