c# – Is it bad practice to cache an entire Model in IIS?

Question:

In an application I use a code like

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

So that's why I created a controller that returns:

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

It was extremely fast, but I'm saving the entire model in cache, imagining that different id will be around 300, so it will be 300 x Model in memory in IIS. Remember that in the past it was not recommended to store entire RecordSets in Session, in theory I'm not doing that?

Now I don't know what is better, fetching 6000x from the database or storing 300model in memory.

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

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

Answer:

From what's available here , Outputcache only stores the return of your action (whether it's html, json, etc) and not objects.

In your case, you're avoiding a database query (which is always good, even more using entity, which uses a lot of memory resources).

Whenever possible by your application logic, use Outputcache to reduce server resources usage.

About changing Outputcache options or monitoring its memory usage .

Scroll to Top
AllEscort