Расширить OutputCacheAttribute в MVC 3 - PullRequest
0 голосов
/ 27 июля 2011

Какой механизм кэширования использует OutputCacheAttribute и как я могу его расширить?

1 Ответ

0 голосов
/ 27 июля 2011

Он использует кэширование ASP.NET WebForm, и вы можете расширить его, переопределив OnResultExecuting.

См .:

Извлечение кода из вышеуказанной ссылки.

public override void OnResultExecuting(ResultExecutingContext filterContext) {
    if (filterContext == null) {
      throw new ArgumentNullException("filterContext");
    }

    if (!filterContext.IsChildAction) {
        // we need to call ProcessRequest() since there's no other way to set the Page.Response intrinsic
        using (OutputCachedPage page = new OutputCachedPage(_cacheSettings)) {
            page.ProcessRequest(HttpContext.Current);
        }
    }
}

private sealed class OutputCachedPage : Page {
    private OutputCacheParameters _cacheSettings;

    public OutputCachedPage(OutputCacheParameters cacheSettings) {
        // Tracing requires Page IDs to be unique.
        ID = Guid.NewGuid().ToString();
        _cacheSettings = cacheSettings;
    }

    protected override void FrameworkInitialize() {
        // when you put the <%@ OutputCache %> directive on a page, the generated code calls InitOutputCache() from here
        base.FrameworkInitialize();
        InitOutputCache(_cacheSettings);
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...