mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-11-08 10:24:44 +08:00
add missing files
This commit is contained in:
44
Infrastructure/Cache/CacheContext.cs
Normal file
44
Infrastructure/Cache/CacheContext.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
|
||||
namespace Infrastructure.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// 策略模式缓存组件,可实现动态插拔
|
||||
/// </summary>
|
||||
public abstract class CacheContext : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化缓存组件
|
||||
/// </summary>
|
||||
public abstract void Init();
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存项
|
||||
/// </summary>
|
||||
/// <typeparam name="T">缓存对象类型</typeparam>
|
||||
/// <param name="key">键</param>
|
||||
/// <returns>缓存对象</returns>
|
||||
public abstract T Get<T>(string key) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 设置缓存项
|
||||
/// </summary>
|
||||
/// <typeparam name="T">缓存对象类型</typeparam>
|
||||
/// <param name="key">键</param>
|
||||
/// <param name="t">缓存对象</param>
|
||||
/// <returns>true成功,false失败</returns>
|
||||
public abstract bool Set<T>(string key, T t) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 移除一个缓存项
|
||||
/// </summary>
|
||||
/// <param name="key">缓存项key</param>
|
||||
/// <returns>true成功,false失败</returns>
|
||||
public abstract bool Remove(string key);
|
||||
|
||||
/// <summary>
|
||||
/// 释放缓存组件
|
||||
/// </summary>
|
||||
public abstract void Dispose();
|
||||
}
|
||||
}
|
||||
49
Infrastructure/Cache/EnyimMemcachedContext.cs
Normal file
49
Infrastructure/Cache/EnyimMemcachedContext.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : Infrastructure
|
||||
// Author : yubaolee
|
||||
// Created : 06-21-2016
|
||||
//
|
||||
// Last Modified By : yubaolee
|
||||
// Last Modified On : 06-21-2016
|
||||
// Contact :
|
||||
// File: EnyimMemcachedContext.cs
|
||||
// ***********************************************************************
|
||||
|
||||
|
||||
using Enyim.Caching;
|
||||
using Enyim.Caching.Memcached;
|
||||
|
||||
namespace Infrastructure.Cache
|
||||
{
|
||||
public sealed class EnyimMemcachedContext : CacheContext
|
||||
{
|
||||
private readonly MemcachedClient _memcachedClient = new MemcachedClient("memcached");
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
}
|
||||
|
||||
public override T Get<T>(string key)
|
||||
{
|
||||
return _memcachedClient.Get<T>(key);
|
||||
}
|
||||
|
||||
public override bool Set<T>(string key, T t)
|
||||
{
|
||||
return _memcachedClient.Store(StoreMode.Set, key, t);
|
||||
}
|
||||
|
||||
public override bool Remove(string key)
|
||||
{
|
||||
return _memcachedClient.Remove(key);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
if (_memcachedClient != null)
|
||||
{
|
||||
_memcachedClient.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
61
Infrastructure/Cache/SessionContext.cs
Normal file
61
Infrastructure/Cache/SessionContext.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : Infrastructure
|
||||
// Author : yubaolee
|
||||
// Created : 06-21-2016
|
||||
//
|
||||
// Last Modified By : yubaolee
|
||||
// Last Modified On : 06-21-2016
|
||||
// Contact :
|
||||
// File: EnyimMemcachedContext.cs
|
||||
// ***********************************************************************
|
||||
|
||||
|
||||
using System;
|
||||
using System.Web;
|
||||
|
||||
namespace Infrastructure.Cache
|
||||
{
|
||||
public sealed class SessionContext : CacheContext
|
||||
{
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
}
|
||||
|
||||
public override T Get<T>(string key)
|
||||
{
|
||||
return (T) HttpContext.Current.Application[key];
|
||||
}
|
||||
|
||||
public override bool Set<T>(string key, T t)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpContext.Current.Application[key] = t;
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Remove(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpContext.Current.Application[key] = null;
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user