Cache Wrapper with expressions

Posted by Fujiy on Stack Overflow See other posts from Stack Overflow or by Fujiy
Published on 2010-04-06T10:45:19Z Indexed on 2010/04/06 11:23 UTC
Read the original article Hit count: 301

Filed under:
|
|

I dont know if is possible.

I want a class to encapsulate all Cache of my site. I thinking about the best way to do this to avoid conflict with keys.

My first idea is something like this:

    public static TResult Cachear<TResult>(this Cache cache, Expression<Func<TResult>> funcao)
    {
        string chave = funcao.ToString();

        if (!(cache[chave] is TResult))
        {
            cache[chave] = funcao.Compile()();
        }

        return (TResult)cache[chave];
    }

Is the best way? Ty

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#