Esempio n. 1
0
        public static void UpdateCacheLine(string id, DateTime validUntil, string data)
        {
            CacheLine line = null;

            using (CacheDbContext ctx = new CacheDbContext())
            {
                line = ctx.CacheLines.Where(e => string.Equals(e.Id, id)).FirstOrDefault();
            }
            if (line is null)
            {
                line = new CacheLine
                {
                    Id         = id,
                    ValidUntil = validUntil,
                    Data       = data
                };
                line.Add();
            }
            else
            {
                line.ValidUntil = validUntil;
                line.Data       = data;
                line.Update();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Checks if there exists a <see cref="CacheLine"/> for the given <paramref name="id"/> which is still valid.
        /// </summary>
        /// <param name="id">The ID of the <see cref="CacheLine"/>.</param>
        /// <returns>The cached data in case there exists a valid <see cref="CacheLine"/>. Else, null.</returns>
        public static string GetCacheLine(string id)
        {
            CacheLine line = null;

            using (CacheDbContext ctx = new CacheDbContext())
            {
                line = ctx.CacheLines.Where(e => string.Equals(e.Id, id)).FirstOrDefault();
            }
            return(!(line is null) && (line.ValidUntil > DateTime.Now) ? line.Data : null);
        }