Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard 3rd party Python caching class?

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.

like image 910
Salim Fadhley Avatar asked Oct 14 '22 16:10

Salim Fadhley


1 Answers

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.

UPDATE 3: It's probably a bit late to be of use to you, but a previous employer of mine used ZODB for this kind of thing. It's an actual database, but its read performance is fast enough to make it useful for caching.

like image 88
Jason Baker Avatar answered Oct 20 '22 09:10

Jason Baker