using System;
using System.Runtime.Caching;
namespace TestWebApp.Service
{
public class MemoryCacheService
{
static ObjectCache cache = MemoryCache.Default;
/// <summary>
/// 获取缓存值
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
private object GetCacheValue(string key)
{
if (key != null && cache.Contains(key))
{
return cache[key];
}
return default(object);
}
/// <summary>
/// 添加缓存内容
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public static void SetChacheValue(string key, object value)
{
if (key != null)
{
CacheItemPolicy policy = new CacheItemPolicy
{
SlidingExpiration = TimeSpan.FromHours(1)
};
cache.Set(key, value, policy);
}
}
}
}
using Microsoft.Extensions.Caching.Memory;
static ObjectCache cache = MemoryCache.Default;
static MemoryCache cache = new MemoryCache(new MemoryCacheOptions());
private object GetCacheValue(string key)
{
if (key != null && cache.Contains(key))
{
return cache[key];
}
return default(object);
}
private object GetCacheValue(string key)
{
object val = null;
if (key != null && cache.TryGetValue(key, out val))
{
return val;
}
else
{
return default(object);
}
}
public static void SetChacheValue(string key, object value)
{
if (key != null)
{
CacheItemPolicy policy = new CacheItemPolicy
{
SlidingExpiration = TimeSpan.FromHours(1)
};
cache.Set(key, value, policy);
}
}
public static void SetChacheValue(string key, object value)
{
if (key != null)
{
cache.Set(key, value, new MemoryCacheEntryOptions
{
SlidingExpiration = TimeSpan.FromHours(1)
});
}
}
using Microsoft.Extensions.Caching.Memory;
using System;
namespace TestMemoryCacheWebApp.Services
{
public class MemoryCacheService
{
static MemoryCache cache = new MemoryCache(new MemoryCacheOptions());
/// <summary>
/// 获取缓存值
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
private object GetCacheValue(string key)
{
object val = null;
if (key != null && cache.TryGetValue(key, out val))
{
return val;
}
else
{
return default(object);
}
}
/// <summary>
/// 添加缓存内容
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public static void SetChacheValue(string key, object value)
{
if (key != null)
{
cache.Set(key, value, new MemoryCacheEntryOptions
{
SlidingExpiration = TimeSpan.FromHours(1)
});
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有