/// <inheritdoc />
        public bool Equals(CacheResult <TOperation, TReturn> other)
        {
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if (ReferenceEquals(other, null))
            {
                return(false);
            }

            var result = this.Operation.IsEqualTo(other.Operation) &&
                         this.CachedObject.IsEqualTo(other.CachedObject) &&
                         this.FreshnessInUtc.IsEqualTo(other.FreshnessInUtc);

            return(result);
        }
示例#2
0
 /// <inheritdoc />
 public CacheResult <TOperation, TReturn> Execute(
     GetOrAddCachedItemOp <TOperation, TReturn> operation)
 {
     lock (this.syncCache)
     {
         var found = this.operationToCacheResultMap.TryGetValue(operation.Operation, out var result);
         if (found)
         {
             return(result);
         }
         else
         {
             var newResult      = this.protocol.Execute(operation.Operation);
             var newCacheResult = new CacheResult <TOperation, TReturn>(operation.Operation, newResult, DateTime.UtcNow);
             this.operationToCacheResultMap.Add(operation.Operation, newCacheResult);
             return(newCacheResult);
         }
     }
 }