This commit is contained in:
Zel
2025-02-23 18:47:21 +08:00
parent eaaffeeccb
commit e46a7ca31c
104 changed files with 2630 additions and 2516 deletions

View File

@@ -4,6 +4,9 @@ using System.Runtime.Caching;
namespace ZelWiki.Caching
{
/// <summary>
/// 缓存
/// </summary>
public class WikiCache
{
public enum Category
@@ -24,7 +27,7 @@ namespace ZelWiki.Caching
public static int CacheItemCount => MemCache.Count();
public static double CacheMemoryLimit => MemCache.CacheMemoryLimit;
public static MemoryCache MemCache => _memCache ?? throw new Exception("Cache has not been initialized.");
public static MemoryCache MemCache => _memCache ?? throw new Exception("缓存尚未初始化");
public static void Initialize(int cacheMemoryLimitMB, int defaultCacheSeconds)
{
@@ -40,7 +43,7 @@ namespace ZelWiki.Caching
}
/// <summary>
/// Gets an item from the cache.
/// 获取缓存
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="cacheKey"></param>
@@ -60,9 +63,8 @@ namespace ZelWiki.Caching
}
/// <summary>
/// Determines if the cache contains a given key.
/// 确定缓存是否包含给定的key
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="cacheKey"></param>
/// <returns></returns>
public static bool Contains(IWikiCacheKey cacheKey)
@@ -79,7 +81,7 @@ namespace ZelWiki.Caching
}
/// <summary>
/// Gets an item from the cache.
/// 获取缓存
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="cacheKey"></param>
@@ -98,7 +100,7 @@ namespace ZelWiki.Caching
}
/// <summary>
/// Adds an item to the cache. If the item is already in the cache, this will reset its expiration.
///添加缓存
/// </summary>
/// <param name="cacheKey"></param>
/// <param name="value"></param>
@@ -127,7 +129,7 @@ namespace ZelWiki.Caching
}
/// <summary>
/// Removes all entries from the cache.
/// 清理
/// </summary>
public static void Clear()
{
@@ -144,9 +146,9 @@ namespace ZelWiki.Caching
}
/// <summary>
/// Removes cache entries that begin with the given cache key.
/// 删除某个
/// </summary>
/// <param name="category"></param>
/// <param name="cacheKey"></param>
public static void ClearCategory(WikiCacheKey cacheKey)
{
var keys = new List<string>();
@@ -163,7 +165,7 @@ namespace ZelWiki.Caching
}
/// <summary>
/// Removes cache entries in a given category.
/// 删除给定类别中的缓存条目
/// </summary>
/// <param name="category"></param>
public static void ClearCategory(Category category)
@@ -183,4 +185,4 @@ namespace ZelWiki.Caching
keys.ForEach(o => MemCache.Remove(o));
}
}
}
}