Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8893839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:20:55+00:00 2026-06-14T23:20:55+00:00

I am trying to enable RavenDB Aggressive Caching in a WebApi application, for a

  • 0

I am trying to enable RavenDB Aggressive Caching in a WebApi application, for a single action method within a larger application.

In order to achieve this, I went the route of creating an action filter attribute, which gets the IDocumentSession, and in OnActionExecuting invokes the method to enable Aggressive Caching for 15 minutes. Then, in OnActionexecuted, I call DisableAggressiveCaching() on the same session.

In short, this has resulted in some fairly weird behaviour. After the action method that uses Aggressive Caching has been called, subsequent requests to other action methods, that do not in anyway rely on the cache (they are making completely different requests), end up getting an IDocumentSession where the AggressiveCacheDuration is 15mins. The frequency with which this happens seems proportional to the number of times that the cached action method has been called previously. I should add, I am using StructureMap for DI, using an IDocumentStore singleton, and injecting a HttpContextScoped IDocumentSession. I’ve confirmed that a new IDocumentSession is being injected each and every request, yet some of them have caching enabled.

Some code to try and elaborate further…

IoC – RavenRegistry

var documentStore = new DocumentStore {ConnectionStringName = "RavenDB"};

documentStore.Initialize();

For<IDocumentStore>().Singleton().Use(documentStore);
For<IDocumentSession>().HttpContextScoped().Use(x =>
{
    var store = x.GetInstance<IDocumentStore>();
    var session =  store.OpenSession();
    return session;
});

AggressivelyCacheAttribute

public class AggressivelyCacheAttribute : ActionFilterAttribute
{
    private IDocumentSession _documentSession;

    public override void OnActionExecuting(HttpActionContext actionContext)
    {
        base.OnActionExecuting(actionContext);

        _documentSession = actionContext.Request.GetDependencyScope()
            .GetService(typeof(IDocumentSession)) as IDocumentSession;

        _documentSession.Advanced.DocumentStore
            .AggressivelyCacheFor(TimeSpan.FromMinutes(15));
    }

    public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
    {
        base.OnActionExecuted(actionExecutedContext);
        _documentSession.Advanced.DocumentStore.DisableAggressiveCaching();
    }
}

The same IDocumentSession is then used later in the pipeline to query the database, the results of which are cached.

In subsequent request, on methods where the attribute is not present, the injected IDocumentSession has caching set to 15mins. Why is this so?

The only examples I have seen online are where the session is created, with caching, inside a using statement. Is that the only ‘safe’ way to use Aggressive Caching, or is it possible to do what I’m trying? If so, how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:20:56+00:00Added an answer on June 14, 2026 at 11:20 pm

    Based on Ayende’s blogging platform code, you need to have a reference in your filter class:

    private IDisposable _cachingHandle;
    

    Then when you make the caching declaration, assign the result to that:

    _cachingHandle  = _documentSession.Advanced.DocumentStore
        .AggressivelyCacheFor(TimeSpan.FromMinutes(15));
    

    Then in your Executed,

    if(_cachingHandle != null)
        _cachingHandle.Dispose();
    

    That should stop the unwanted caching.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to enable the delete key in my treeview. This is what
I'm trying to enable my application to keep previous versions of entities. For example,
I am trying to enable SQL Debugging following this link http://msdn.microsoft.com/en-us/library/ms165038%28VS.80%29.aspx but i can't
I am trying to enable/disable radiobuttonlist with javascript code. This javascript is working fine
I am trying to enable the row caching for some of the CFs in
I'm trying to enable caching for images and the like on my web server,
We are trying to enable HTTP compression (gzip) and HTTP 304 Caching via ETags
Hello im trying to enable my JMenuItem from within an event listener but it
I'm trying to enable XRankNTypes in GHCi. How do I do this?
I am trying to enable JIT debugging for my winform application, I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.