Custom OutputCache provider generates different keys in Add () vs Set () function

I am writing a custom OutputCacheProvider in MVC3.

Calls are triggered in the following order: Get, Add, Set. I expect the generated keys to be the same in all methods, but they are not. The problem is that in different calls to Get and Add it is called with a different key than in the Set method.

My request looks like this: http://localhost/testCall?startIndex=0&maxResults=25&testParam=4

With the VaryByParam set, I expect the key to be unique based on my query parameters to look something like this: testCall?startIndex=0&maxResults=25&testParam=4

Instead, in Get / Add calls, the key only has the fully qualified pathname: localhost/testCall

But in the call to Set, the key really looks like what I expect: local/testCallHQNmaxresultsV25NstartindexV0NtestparamV4FCDE

Here's my controller method.

[OutputCache(Duration = 15, VaryByParam = "*")]
public ActionResult TestOutputCache()
{
    var obj = new List<string>() {"test", "one", "two", "three"};
    return Json(obj);
}

      

Here's my custom OutputCacheProvider

public class MemcacheOutputCacheProvider : OutputCacheProvider
{
    public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
    {
        base.Initialize(name, config);
    }

    public override object Get(string key)
    {
        // UNEXPECTED, the key = "localhost/testCall"
        return null;
    }

    public override object Add(string key, object entry, DateTime utcExpiry)
    {
        // UNEXPECTED, the key = "localhost/testCall"
        return null;
    }

    public override void Set(string key, object entry, DateTime utcExpiry)
    {
        // EXPECTED, the key = "local/testCallHQNmaxresultsV25NstartindexV0NtestparamV4FCDE"
    }

    public override void Remove(string key)
    {
    }
}   

      

If the call to Set is made with the correct parameters, but Get () is never called with the correct key, then caching will only work on the root call / testCall

+3


source to share





All Articles