ChrisA wrote:
Otis wrote:
Take a look at the Context class sourcecode, it contains an entity cache.
I'm caching Collections though, but as ArrayLists... I'm not sure if you mean the .Net Context class, or some LLBLGen Context class (which I can't seem to find if there is one....)
The LLBLGen Pro Context class, in the ORMSupport classes (introduced in 1.0.2004.2).
It uses a double hashtable structure internally to cache entities, per type.
I'm a little confused and a relative newbie, so clue me in a little more on what you are referencing so I can look into it more...
Caching is in fact pretty simple. You have to have a store in which you store per key an object, which is then cached under that key and because you use a key system, it's very fast to retrieve a cached object again.
Collections don't have a unique object id, so identifying is not easy unless you use a system where you provide the key under which a collection is stored.
You then use internally a hashtable. For example, for caching all country entities, you could file that collection under 'Countries'.
Be aware that if you use your cache in a multi-threaded environment, multiple threads will get a reference to the same collection. It's therefore key that the data which is cached is only used read-only, including the collection itself.