Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic cache of objects

Tags:

c++

stl

boost

Does anyone know any implementation of a templated cache of objects?

  • You use a key to find object (the same as in std::map<>)
  • You specify a maximum number of objects that can be in the cache at the same time
  • There are facilities to create an object not found in the cache
  • There are facilities to know when an object is discarded from the cache

For example :

typedef cache<int, MyObj*> MyCache;
MyCache oCache;
oCache.SetSize(1);
oCache.Insert(make_pair(1, new MyObj());
oCache.Touch(1);
MyObj* oldObj = oCache.Delete(1);

...

It can be as simple as a LRU or MRU cache.

Any suggestions are welcomed!

Nic

like image 323
Nicolas Avatar asked Sep 23 '08 18:09

Nicolas


People also ask

What are cache objects?

An object cache is a recently used object definition stored in memory on Developer and Intelligence Server. You browse an object definition when you open the editor for that object. You can create object caches for applications.

What are the two types of caching?

Object Caching : Object caching is caching the objects on a page, such as data-bound controls. The cached data is stored in server memory. Class Caching : Web pages or web services are compiled into a page class in the assembly, when run for the first time. Then the assembly is cached in the server.


1 Answers

You can use the Boost.MultiIndex library. It is easy to implement a MRU cache.

like image 87
david.jugon Avatar answered Sep 22 '22 15:09

david.jugon