tags:

views:

612

answers:

3

I'm doing some design (initially for Java) (but may extend to .NET in the future?) and I'm getting confused between the terms "cache" and "pool".

As far as I can see, the main point of difference is what is contained in them?

Any guidelines as to which should be used when?

And what then is a "cache pool" which is referred to in a number of articles?

+1  A: 

Cache is generally for saving the results of expensive operations or to optimize retrieval of those results.

Pool is used to describe a collection of resources that is available for one or more applications to use but allows for control of the number of these resources.

I've not run across the term "cache pool" - but based on a quick review, it appears to used for a pool of caches, or a collection of caches managed by a pool.

Ken Gentle
A: 

I agree with Ken, and to add a little--a Cache would not effect your system if some or all of the resources were removed from it at any time--the data is all easily reproducable/refetchable, and the reproducing is generally automatic (you ask the cache for something, if it doesn't exist in the cache, the cache makes one, saves it and returns it to you).

A "Pool" can be anything, but you don't just delete pool objects because they are old--usually a pool contains unique, maybe unreproducible instances of some resource.

Bill K
Typically a pool contains expensive-to-create objects. I would disagree that the items in the pool are 'unique or unreproducible' in the general sense.
Robert Paulson
Then how would you differentiate it from a cache?
Bill K
Read my answer, but it's only semantics. A cache only cares about lifetime and becoming stale and storing results temporarily You shove things in a cache. Pooled items don't normally become stale, and they are for sharing a resource that is managed by the pool. But don't take my word word it.
Robert Paulson
+4  A: 

Although they both refer to keeping objects around, they are quite different, and I wouldn't say they're interchangeable.

Cache - store frequently used values, typically because the lookup and/or creation is non-trivial. e.g. if a lookup table from a database is frequently used, or values are read from a file on disk, it's more efficient to keep it in memory and refresh it periodically.

A cache only manages object lifetime in the cache, but does not impose semantics on what is held in the cache. A cache also doesn't create the items, but just stores objects.

Pool - term to describe a group of resources that are managed by the pool itself. e.g. (Database) Connection Pool - When a connection is needed it is obtained from the pool, and when finished with is returned to the pool.

The pool itself handles creation and destruction of the pooled objects, and manages how many objects can be created at any one time.

Cache Pool - mostly seems to describe the number of (independent?) cache's that exist. E.g. an asp.net application has 1 cache per Application Domain (cache isn't shared between asp.net applications). Literally a pool of caches, although this term seems to be used rarely.

Robert Paulson