views:

381

answers:

1

I'm working on a client class which needs to load data from a networked database. It's been suggested that adding a standard caching service to the client could improve it's performance.

I'd dearly like not to have to build my own caching class - it's well known that these provide common points of failure. It would be far better to use a class that somebody else has developed rather than spend a huge amount of my own time debugging a home-made caching system.

Java developers have this: http://ehcache.sourceforge.net/

It's a general purpose high-performance caching class which can support all kinds of storage. It's got options for time-based expiry and other methods for garbage-collecting. It looks really good. Unfortunately I cannot find anything this good for Python.

So, can somebody suggest a cache-class that's ready for me to use. My wish-list is:

  • Ability to limit the number of objects in the cache.
  • Ability to limit the maximum age of objects in the cache.
  • LRU object expirey
  • Ability to select multiple forms of storage ( e.g. memory, disk )
  • Well debugged, well maintained, in use by at least one well-known application.
  • Good performance.

So, any suggestions?

UPDATE: I'm looking for LOCAL caching of objects. The server which I connect to is already heavily cached. Memcached is not appropriate because it requires an additional network traffic between the Windows client and the server.

+4  A: 

I'd recommend using memcached and using cmemcache to access it. You can't necessarily limit the number of objects in the cache, but you can set an expiration time and limit the amount of memory it uses. And memcached is used by a lot of big names. In fact, I'd call it kind of the industry standard.

UPDATE:

I'm looking for LOCAL caching of objects.

You can run memcached locally and access it via localhost. I've done this a few times.

Other than that, the only solution that I can think of is django's caching system. It offers several backends and some other configuration options. But that may be a little bit heavyweight if you're not using django.

UPDATE 2: I suppose as a last resort, you can also use jython and access the java caching system. This may be a little difficult to do if you've already got clients using CPython though.

Jason Baker
That's not appropriate in this case... I'm trying to speed up a network application by adding a LOCAL cache. A network cache is going to be slow for end users given that they could be anywhere in the world.
Salim Fadhley
Sadly, it is to complex to use Jython at this stage.
Salim Fadhley