private void Write(KeyValueContainer container)
        {
            var lifetime          = GetLifetime(container);
            var cacheEntryOptions = new MemoryCacheEntryOptions()
                                    .SetSlidingExpiration(lifetime);

            MemoryCache.Set(container.Key, container, cacheEntryOptions);
        }
        public KeyValueContainer Insert(KeyValueContainer container)
        {
            var generateKeyForUser = string.IsNullOrEmpty(container.Key);

            if (generateKeyForUser)
            {
                container.Key = Guid.NewGuid().ToString();
            }

            Write(container);
            return(container);
        }
 public ResponseObject <KeyValueContainer> Insert([FromBody] KeyValueContainer container)
 {
     try
     {
         var repository = RocketServiceProvider.GetService <Repository>();
         return(GetSuccessResponse(repository.Insert(container)));
     }
     catch (Exception e)
     {
         return(GetErrorResponse <KeyValueContainer>(e));
     }
 }
        private TimeSpan GetLifetime(KeyValueContainer container)
        {
            var  lifetimeExplicitlySpecified = container.LifetimeSeconds > 0;
            long lifetimeSeconds;

            if (lifetimeExplicitlySpecified)
            {
                lifetimeSeconds = container.LifetimeSeconds;
            }
            else
            {
                var oneMinuteSeconds = 60;
                var oneHourSeconds   = oneMinuteSeconds * 60;
                var fourHourSeconds  = oneHourSeconds * 4;
                lifetimeSeconds = fourHourSeconds;
            }
            return(TimeSpan.FromSeconds(lifetimeSeconds));
        }