I’d like to maintain an object/connection pool in an ASP.NET MVC application. The purpose of the pool is to improve performance by reusing connections to a third-party web service. The third-party web service requires a login call which returns a session ID – the pool saves these session IDs.
My question is, where do I instantiate this object pool so that it can be used across all requests? It will only be used by 1 controller but if I instantiate it in the controller I believe a new object pool will be instantiated for every user request even if it is a singleton?
Is it reasonable to store it in the Application state?
What you are referring to as an object pool has a name: it’s often called cache.
You could use the
ObjectCacheclass and more specifically the MemoryCache class which is one implementation of it.