Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/DR.Sleipner.EnyimMemcachedProvider/EnyimMemcachedProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public EnyimMemcachedProvider(IMemcachedClient client)

public CachedObject<TResult> GetItem<TResult>(ProxyRequest<T, TResult> proxyRequest, CachePolicy cachePolicy)
{
var key = proxyRequest.CreateHash();
var key = proxyRequest.CreateHash(cachePolicy.CachePool);

object value;
if (_client.TryGet(key, out value))
Expand Down Expand Up @@ -56,7 +56,7 @@ public CachedObject<TResult> GetItem<TResult>(ProxyRequest<T, TResult> proxyRequ

public void StoreItem<TResult>(ProxyRequest<T, TResult> proxyRequest, CachePolicy cachePolicy, TResult item)
{
var key = proxyRequest.CreateHash();
var key = proxyRequest.CreateHash(cachePolicy.CachePool);
var cachedObject = new MemcachedObject<TResult>()
{
Created = DateTime.Now,
Expand All @@ -75,7 +75,7 @@ public void StoreItem<TResult>(ProxyRequest<T, TResult> proxyRequest, CachePolic

public void StoreException<TResult>(ProxyRequest<T, TResult> proxyRequest, CachePolicy cachePolicy, Exception exception)
{
var key = proxyRequest.CreateHash();
var key = proxyRequest.CreateHash(cachePolicy.CachePool);
var cachedObject = new MemcachedObject<TResult>()
{
Created = DateTime.Now,
Expand All @@ -93,13 +93,13 @@ public void StoreException<TResult>(ProxyRequest<T, TResult> proxyRequest, Cache
}
}

public void Purge<TResult>(Expression<Func<T, TResult>> expression)
public void Purge<TResult>(Expression<Func<T, TResult>> expression, string cachePool)
{
var methodInfo = SymbolExtensions.GetMethodInfo(expression);
var parameters = SymbolExtensions.GetParameter(expression);
var proxyExpression = new ProxyRequest<T, TResult>(methodInfo, parameters);

var hash = proxyExpression.CreateHash();
var hash = proxyExpression.CreateHash(cachePool);
_client.Remove(hash);
}

Expand All @@ -116,9 +116,9 @@ public void Exterminatus()
throw new NotImplementedException("Exterminatus cannot be performed on a memcached based provider (it would exterminate the entire memcached cluster)");
}

public bool TryGetRaw<TResult>(ProxyRequest<T, TResult> proxyRequest, out object result)
public bool TryGetRaw<TResult>(ProxyRequest<T, TResult> proxyRequest, out object result, string cachePool)
{
var key = proxyRequest.CreateHash();
var key = proxyRequest.CreateHash(cachePool);
object value;
if (_client.TryGet(key, out value))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ namespace DR.Sleipner.EnyimMemcachedProvider
{
public static class ProxyRequestExtensions
{
public static string CreateHash<T, TResult>(this ProxyRequest<T, TResult> proxyRequest) where T : class
public static string CreateHash<T, TResult>(this ProxyRequest<T, TResult> proxyRequest, string cachePool) where T : class
{
var sb = new StringBuilder();
sb.Append(typeof (T).FullName);
sb.Append(" - ");
sb.Append(proxyRequest.Method);
if (!string.IsNullOrWhiteSpace(cachePool))
{
sb.Append(" - ");
sb.Append(cachePool);
}
sb.Append(" - ");
sb.AddParameterRepresentations(proxyRequest.Parameters);


var bytes = Encoding.UTF8.GetBytes(sb.ToString());
var hashAlgorithm = new SHA256Managed();
Expand Down
1 change: 1 addition & 0 deletions src/DR.Sleipner/CachePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public class CachePolicy
public int MaxAge;
public int ExceptionCacheDuration = 10;
public bool BubbleExceptions;
public string CachePool = "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void StoreException<TResult>(ProxyRequest<T, TResult> proxyRequest, Cache
_cache[cacheKey] = new DictionaryCachedItem(exception, duration, absoluteDuration);
}

public void Purge<TResult>(Expression<Func<T, TResult>> expression)
public void Purge<TResult>(Expression<Func<T, TResult>> expression, string cachePool)
{
var methodInfo = SymbolExtensions.GetMethodInfo(expression);
var parameters = SymbolExtensions.GetParameter(expression);
Expand All @@ -76,7 +76,7 @@ public void Exterminatus()
_cache.Clear();
}

public bool TryGetRaw<TResult>(ProxyRequest<T, TResult> proxyRequest, out object result)
public bool TryGetRaw<TResult>(ProxyRequest<T, TResult> proxyRequest, out object result, string cachePool)
{
var cacheKey = new DictionaryCacheKey(proxyRequest.Method, proxyRequest.Parameters);
if (_cache.ContainsKey(cacheKey))
Expand Down
4 changes: 2 additions & 2 deletions src/DR.Sleipner/CacheProviders/ICacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public interface ICacheProvider<T> where T : class
void StoreItem<TResult>(ProxyRequest<T, TResult> proxyRequest, CachePolicy cachePolicy, TResult item);
void StoreException<TResult>(ProxyRequest<T, TResult> proxyRequest, CachePolicy cachePolicy, Exception exception);

void Purge<TResult>(Expression<Func<T, TResult>> expression);
void Purge<TResult>(Expression<Func<T, TResult>> expression, string cachePool = "");
CachedObjectState GetItemState(Expression<Action<T>> action);
void Exterminatus();

bool TryGetRaw<TResult>(ProxyRequest<T, TResult> proxyRequest, out object result);
bool TryGetRaw<TResult>(ProxyRequest<T, TResult> proxyRequest, out object result, string cachePool = "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@ public interface IMethodFamilyConfigurationExpression
/// </summary>
/// <returns></returns>
IMethodFamilyConfigurationExpression BubbleExceptionsWhenStale();

/// <summary>
/// This is used to set a cachepool name.
/// </summary>
/// <returns></returns>
IMethodFamilyConfigurationExpression CachePool(string name);
}
}
7 changes: 7 additions & 0 deletions src/DR.Sleipner/Config/MethodFamilyConfigExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,12 @@ public IMethodFamilyConfigurationExpression BubbleExceptionsWhenStale()

return this;
}

public IMethodFamilyConfigurationExpression CachePool(string name)
{
_policy.CachePool = name;

return this;
}
}
}