Exemplo n.º 1
0
        public static bool TryGetValue(string path, DiskCacheItem config, out string?cachedResult)
        {
            cachedResult = null;
            if (sessionCache.ContainsKey(path))
            {
                cachedResult = sessionCache[path];
                return(true);
            }

            if (!config.DoCache)
            {
                return(false);
            }

            if (!File.Exists(path))
            {
                return(false);
            }

            TimeSpan age = DateTime.Now - File.GetLastWriteTime(path);

            if (age > config.MaxAge)
            {
                return(false);
            }

            cachedResult = File.ReadAllText(path);
            return(true);
        }
Exemplo n.º 2
0
        public static bool TryGetValue <T>(string path, DiskCacheItem config, [NotNullWhen(true)] out T?cachedResult) where T : class
        {
            if (!TryGetValue(path, config, out string?resultStr))
            {
                cachedResult = default;
                return(false);
            }

            cachedResult = JsonConvert.DeserializeObject <T>(resultStr !);
            return(true);
        }