Having multiple processes, using the same cache (memcached in this case). Those processes are:
- A ASP.NET MVC 4 application
- A Console application
How could I generate the cache keys?
I've been thinking about using a strategy that takes the name of the assembly, full type name, method name and it's parameters. That would look something like:
public static string GenerateKeyFor<T>(Expression<Action<T>> expr)
{
var method = Symbols.GetMethodInfo(expr);
var parameters = Symbols.GetParameters(expr);
var sb = new StringBuilder();
sb.Append(method.DeclaringType.FullName)
.Append(" - ")
.Append(method.Name)
.Append(" - ");
return parameters
.Aggregate(sb, AddParams)
.ToString();
}
Usage:
var key = CacheUtils.GenerateKeyFor<HomeController>(x => x.List());
However, if I then want to evict ex. a ActionResult in the ASP.NET MVC application, from the Console application, then I would need to reference the ASP.NET MVC application in my Console application, in order to could reference the HomeController type. Is there a better way to generate keys for such scenarios?