forked from fordlee/UCsoft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
243 changed files
with
57,296 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Web; | ||
using System.Web.Caching; | ||
|
||
namespace UCsoft.Common | ||
{ | ||
public class CacheHelper | ||
{ | ||
/// <summary> | ||
/// 创建缓存项的文件依赖 | ||
/// </summary> | ||
/// <param name="key">缓存Key</param> | ||
/// <param name="obj">object对象</param> | ||
/// <param name="fileName">文件绝对路径</param> | ||
public static void Insert(string key, object obj, string fileName) | ||
{ | ||
//创建缓存依赖项 | ||
CacheDependency dep = new CacheDependency(fileName); | ||
//创建缓存 | ||
HttpRuntime.Cache.Insert(key, obj, dep); | ||
} | ||
|
||
/// <summary> | ||
/// 创建缓存项过期 | ||
/// </summary> | ||
/// <param name="key">缓存Key</param> | ||
/// <param name="obj">object对象</param> | ||
/// <param name="expires">过期时间(分钟)</param> | ||
public static void Insert(string key, object obj, int expires) | ||
{ | ||
HttpRuntime.Cache.Insert(key, obj, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, expires, 0)); | ||
} | ||
|
||
/// <summary> | ||
/// 获取缓存对象 | ||
/// </summary> | ||
/// <param name="key">缓存Key</param> | ||
/// <returns>object对象</returns> | ||
public static object Get(string key) | ||
{ | ||
if (string.IsNullOrEmpty(key)) | ||
{ | ||
return null; | ||
} | ||
return HttpRuntime.Cache.Get(key); | ||
} | ||
|
||
/// <summary> | ||
/// 获取缓存对象 | ||
/// </summary> | ||
/// <typeparam name="T">T对象</typeparam> | ||
/// <param name="key">缓存Key</param> | ||
/// <returns></returns> | ||
public static T Get<T>(string key) | ||
{ | ||
object obj = Get(key); | ||
return obj == null ? default(T) : (T)obj; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.