コード例 #1
0
        public IEnumerable <Translation> GetAll()
        {
            var translations = _keyValueCache.Get(CacheKey);

            if (translations == null)
            {
                _keyValueCache.Add(CacheKey, _session.Query <Translation>().ToList());
            }

            return(_keyValueCache.Get(CacheKey));
        }
コード例 #2
0
        public IHttpActionResult Post([FromBody] Input value)
        {
            double expiryTime;

            try
            {
                if (value == null)
                {
                    return(BadRequest());
                }
                else
                {
                    if (value.expiryTime != null)
                    {
                        double.TryParse(value.expiryTime.ToString(), out expiryTime);
                        if (_keyValueCache.Add(value.key, value.value, expiryTime))
                        {
                            long expiresAt = DateTimeOffset.Now.AddSeconds(expiryTime).ToUnixTimeSeconds();
                            return(Ok(new JObject(
                                          new JProperty("expiresAt", expiresAt)
                                          )));
                        }
                        return(InternalServerError());
                    }
                    else
                    {
                        return(Ok(new JObject(
                                      new JProperty("expiresAt", null)
                                      )));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CacheController.Post " + ex);
                return(InternalServerError());
            }
        }