MemoryCaching.cs 912 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Extensions.Caching.Memory;
  7. namespace Ropin.Core.Common
  8. {
  9. /// <summary>
  10. /// 实例化缓存接口ICaching
  11. /// </summary>
  12. public class MemoryCaching : ICaching
  13. {
  14. //引用Microsoft.Extensions.Caching.Memory;这个和.net 还是不一样,没有了Httpruntime了
  15. private readonly IMemoryCache _cache;
  16. //还是通过构造函数的方法,获取
  17. public MemoryCaching(IMemoryCache cache)
  18. {
  19. _cache = cache;
  20. }
  21. public object Get(string cacheKey)
  22. {
  23. return _cache.Get(cacheKey);
  24. }
  25. public void Set(string cacheKey, object cacheValue, int timeSpan)
  26. {
  27. _cache.Set(cacheKey, cacheValue, TimeSpan.FromSeconds(timeSpan * 60));
  28. }
  29. }
  30. }