/// <summary> /// 使用本地缓存 /// </summary> /// <param name="absoluteFilePath">生成文件的绝对路径</param> /// <param name="fileContent">文件内容</param> /// <param name="isGenerateFile">是否生成本地文件</param> private static void UseLocalCache(string absoluteFilePath, string fileContent, bool isGenerateFile) { string fullFilePath = null; if (isGenerateFile) { //如果需要生成本地静态文件 NVelocityBus.GenerateFile(absoluteFilePath, fileContent, out fullFilePath);//生成静态文件 } if (string.IsNullOrEmpty(fullFilePath)) { //如果生成文件失败,也放进缓存中(一级缓存),但是放入缓存的时间设置为绝对过期时间。防止频繁请求服务器端占用更多的资源。 DataCacheBus.Insert(absoluteFilePath, fileContent, DateTime.Now.AddMinutes(CACHE_DATETIME)); } else { //如果生成文件成功,放入缓存并设置相对过期时间同时还加上缓存依赖。(一级缓存) DataCacheBus.Insert(absoluteFilePath, fileContent, TimeSpan.FromMinutes(CACHE_DATETIME), fullFilePath); } }