Esempio n. 1
0
        public async Task <IHttpActionResult> Phoenix(string id)
        {
            Phoenix p;

            if (!Global.Cache.PhoenixFireCage.TryGetValue(id, out p))
            {
                return(NotFound());
            }

            var asyncStore = _cacheStoreProvider.GetAsyncCacheStore(p._info.StoreId);

            if (asyncStore != null)
            {
                var unknownCacheObject = await asyncStore.GetAsync(id);

                if (unknownCacheObject is CacheItem)
                {
                    var cacheItemStatus = new CacheItemStatus(unknownCacheObject as CacheItem)
                    {
                        PhoenixStatus = p.GetCurrentState().GetState()
                    };

                    return(Json(cacheItemStatus,
                                new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore,
                        ContractResolver = new CamelCasePropertyNamesContractResolver(),
                        Formatting = Formatting.Indented
                    }));
                }
            }
            return(NotFound());
        }
Esempio n. 2
0
 /// <summary>
 /// Updates the cache item status.
 /// </summary>
 /// <param name="status"></param>
 /// <returns>Returns true if the CacheItemStatus was changed.</returns>
 public bool TrySetCacheItemStatus(CacheItemStatus status)
 {
     lock (_cacheItemStatusLock)
     {
         if (this.CacheItemStatus != status)
         {
             this.CacheItemStatus = status;
             this.UpdatedOn       = DateTimeOffset.UtcNow;
             return(true);
         }
     }
     return(false);
 }
Esempio n. 3
0
        public async Task <IHttpActionResult> Phoenixes()
        {
            var all   = Global.Cache.PhoenixFireCage.ToList();
            var items = new List <CacheItemStatus>();

            foreach (var p in all)
            {
                if (p.Key == null || p.Value == null)
                {
                    continue;
                }

                var cacheItem = p.Value._info;

                var asyncStore = _cacheStoreProvider.GetAsyncCacheStore(p.Value._info.StoreId);
                if (asyncStore != null)
                {
                    var unknownCacheObject = await asyncStore.GetAsync(p.Key);

                    if (unknownCacheObject is CacheItem)
                    {
                        cacheItem = unknownCacheObject as CacheItem;
                    }
                }
                if (cacheItem != null)
                {
                    var status = new CacheItemStatus(cacheItem);
                    status.Key           = p.Key;
                    status.PhoenixStatus = p.Value.GetCurrentState().GetState();
                    status.Type          = p.Value.GetType().Name;
                    if (cacheItem == p.Value._info)
                    {
                        status = status.CacheItemNotFound();
                    }
                    items.Add(status);
                }
            }

            return(Json(items,
                        new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                Formatting = Formatting.Indented
            }));
        }
Esempio n. 4
0
        private void AddTransactionalItem(Func <TItem, bool> match, TItem item, CacheItemStatus status)
        {
            _ = item ?? throw new ArgumentException("item is null", "item");

            Console.WriteLine("DbCache: Adding data to cache: {0}.", item.ToString());
            var newItem = new CacheItemDto <TItem> {
                Updated = DateTime.Now, Status = status, Value = item, MatchItem = match
            };

            lock (locker)
            {
                if (transactionItems?.Add(e => match(e.Value) && e.Status == status, newItem) == true)
                {
                    UpdateAllCacheItems();
                }
                else
                {
                    DoUpdateItems(new[] { newItem });
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Creates a new string cache item.
 /// </summary>
 /// <param name="category">The cache category.</param>
 /// <param name="id">The id.</param>
 /// <param name="item">The item.</param>
 /// <param name="statusCode">The status code.</param>
 /// <param name="expiryTime">The expiry time.</param>
 /// <param name="status">The cache status.</param>
 /// <param name="metadata">The cache metadata.</param>
 public CacheItem(string category, string id, string item, HttpStatusCode statusCode, DateTimeOffset expiryTime, CacheItemStatus status, IDictionary <string, string>?metadata = null)
 {
     this.Category   = category ?? throw new ArgumentNullException(nameof(category));
     this.Id         = id ?? throw new ArgumentNullException(nameof(id));
     this.item       = item ?? throw new ArgumentNullException(nameof(item));
     this.StatusCode = statusCode;
     this.ExpiryTime = expiryTime;
     this.Metadata   = metadata ?? EmptyMetadata;
     this.Type       = CacheItemType.String;
     this.Status     = status;
 }
Esempio n. 6
0
 public void UpdateCacheItem(Func <TItem, bool> match, TItem newItem, CacheItemStatus status = CacheItemStatus.Updated)
 {
     AddTransactionalItem(match, newItem, status);
 }
Esempio n. 7
0
 public GetApprovalStatusResponse(string jwt, CacheItemStatus cacheItemStatus) : base(jwt)
 {
     Status = cacheItemStatus;
 }