From 3866526b959c1ebe7ea5249300f63d6c885cae06 Mon Sep 17 00:00:00 2001 From: zhaojun1998 Date: Sat, 4 Apr 2020 15:57:22 +0800 Subject: [PATCH] =?UTF-8?q?:memo:=20=E8=A1=A5=E5=85=85=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../im/zhaojun/zfile/cache/ZFileCache.java | 84 ++++++++++++++++--- 1 file changed, 74 insertions(+), 10 deletions(-) diff --git a/src/main/java/im/zhaojun/zfile/cache/ZFileCache.java b/src/main/java/im/zhaojun/zfile/cache/ZFileCache.java index 2966a5d..2574b34 100644 --- a/src/main/java/im/zhaojun/zfile/cache/ZFileCache.java +++ b/src/main/java/im/zhaojun/zfile/cache/ZFileCache.java @@ -12,39 +12,75 @@ import java.util.concurrent.ConcurrentMap; /** * @author zhaojun + * ZFile 缓存类 */ @Component public class ZFileCache { - private ConcurrentMap> fileCache = new ConcurrentHashMap<>(); + /** + * 缓存 map 对象. + * key: 文件夹路径 + * value: 文件夹中内容 + */ + private ConcurrentMap> cache = new ConcurrentHashMap<>(); + /** + * 系统设置缓存 + */ private SystemConfigDTO systemConfigCache; + /** + * 缓存最后自动刷新时间 + */ public Date lastCacheAutoRefreshDate; + /** + * 写入缓存 + * @param key 文件夹路径 + * @param value 文件夹中内容 + */ public synchronized void put(String key, List value) { - fileCache.put(key, value); + cache.put(key, value); } + /** + * 根据文件夹路径取的环境 + * @param key 文件夹路径 + * @return 文件夹中内容 + */ public List get(String key) { - return fileCache.get(key); + return cache.get(key); } + /** + * 清空缓存. + */ public void clear() { - fileCache.clear(); + cache.clear(); } + /** + * 获取已缓存文件夹数量 + * @return 已缓存文件夹数量 + */ public int cacheCount() { - return fileCache.size(); + return cache.size(); } + /** + * 搜索缓存中内容 + * @param key 搜索键, 可匹配文件夹名称和文件名称. + * @param ignoreCase 是否忽略大小写, true 为忽略, false 为不忽略. + * @param searchContainEncryptedFile 搜索是否包含加密文件. true 为不包含, false 为包含, 用于控制当文件夹被密码保护时, 是否出现在搜索结果中. + * @return 搜索结果, 包含文件夹和文件. + */ public List find(String key, boolean ignoreCase, boolean searchContainEncryptedFile) { List result = new ArrayList<>(); - Collection> values = fileCache.values(); + Collection> values = cache.values(); for (List fileItemList : values) { - // 如果开启了 "搜索包含加密文件" 选项, 则直接返回 true. + // 过滤加密文件 if (!searchContainEncryptedFile && isEncryptedFolder(fileItemList)) { continue; } @@ -52,6 +88,7 @@ public class ZFileCache { for (FileItemDTO fileItemDTO : fileItemList) { boolean testResult; + // 根据是否需要忽略大小写来匹配文件(夹)名 if (ignoreCase) { testResult = StrUtil.containsIgnoreCase(fileItemDTO.getName(), key); } else { @@ -66,37 +103,64 @@ public class ZFileCache { return result; } + /** + * 获取所有缓存 key (文件夹名称) + * @return 所有缓存 key + */ public Set keySet() { - return fileCache.keySet(); + return cache.keySet(); } + /** + * 从缓存中删除一个条目 + * @param key 文件夹名称 + */ public void remove(String key) { - fileCache.remove(key); + cache.remove(key); } + /** + * 更新缓存中的系统设置 + * @param systemConfigCache 系统设置 + */ public void updateConfig(SystemConfigDTO systemConfigCache) { this.systemConfigCache = systemConfigCache; } + /** + * 从获取中获取系统设置 + * @return 系统设置 + */ public SystemConfigDTO getConfig() { return this.systemConfigCache; } + /** + * 清空系统设置缓存 + */ public void removeConfig() { this.systemConfigCache = null; } + /** + * 获取缓存最后刷新时间 + * @return 缓存最后刷新时间 + */ public Date getLastCacheAutoRefreshDate() { return lastCacheAutoRefreshDate; } + /** + * 更新缓存最后刷新时间 + * @param lastCacheAutoRefreshDate 缓存最后刷新时间 + */ public void setLastCacheAutoRefreshDate(Date lastCacheAutoRefreshDate) { this.lastCacheAutoRefreshDate = lastCacheAutoRefreshDate; } /** - * 不是加密文件夹 + * 判断是否为加密文件夹 * @param list 文件夹中的内容 * @return 返回此文件夹是否加密. */