Is it bad practice to cache an entire Model on IIS?

Asked

Viewed 82 times

3

In an application I use sixteen times a code like

var cliente = db.Clientes.Find(id);

So that’s why I created a controller that returns me:

[OutputCache(Duration = (10 * 60 * 60), VaryByParam = "id")]
    public static Cliente ClienteInfo(int id)
    {
        using (WMBContext db = new WMBContext())
        {
            return db.Clientes.Find(id);
        }
    }

It got extremely fast, but I’m caching the entire model, imagining that different id will be around 300, so it will be 300 x Model in memory on IIS. I remember that in the past it was not recommended to store entire Recordsets in Session, in theory I am not doing this?

Now I don’t know which is better, search 6000x in the database or store 300model in memory.

Is there any way to verify the memory used in the cache? will be linked to the pool? (the code is not yet in production)

Edit OBS: This model has relationships with other models and has more than 30 properties.

  • 1

    I do not see how bad practice, in case the memory of the machine where the IIS is not enough, you can still change the Preview of your Cache. I advise you to take a look at Redisoutputcacheprovider

  • One more thing, a 10-hour cache may not be ideal. and try to invalidate the cache whenever the log changes.

1 answer

1


For what is available here, Outputcache stores only the return of your action (whether html, json, etc.) and not objects.

In your case, you are avoiding a query in the database (which is always good, plus using Entity, which uses a lot of memory resources).

Whenever possible by your application’s logic, use Outputcache to decrease server’s use of Resources.

About change the options of Outputcache or monitor your memory utilization.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.