简体   繁体   English

是否有标准的第 3 方 Python 缓存 class?

[英]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.我正在开发需要从联网数据库加载数据的客户端 class。 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.我非常希望不必构建自己的缓存 class - 众所周知,这些提供了常见的故障点。 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.使用别人开发的 class 比花费大量时间调试自制的缓存系统要好得多。

Java developers have this: http://ehcache.sourceforge.net/ Java 开发者有这个: http://ehcache.sourceforge.net/

It's a general purpose high-performance caching class which can support all kinds of storage.它是一个通用的高性能缓存class,可以支持各种存储。 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.不幸的是,我找不到对 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 LRU object 过期
  • Ability to select multiple forms of storage ( eg memory, disk )能够 select 多个 forms 存储(例如 memory,磁盘)
  • 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. Memcached 不合适,因为它需要 Windows 客户端和服务器之间的额外网络流量。

I'd recommend using memcached and using cmemcache to access it.我建议使用memcached并使用cmemcache来访问它。 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.您不一定要限制缓存中的对象数量,但您可以设置过期时间并限制它使用的 memory 的数量。 And memcached is used by a lot of big names.并且 memcached 被很多大牌使用。 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.您可以在本地运行 memcached 并通过 localhost 访问它。 I've done this a few times.我已经做过几次了。

Other than that, the only solution that I can think of is django's caching system .除此之外,我能想到的唯一解决方案是django 的缓存系统 It offers several backends and some other configuration options.它提供了几个后端和一些其他配置选项。 But that may be a little bit heavyweight if you're not using django.但是,如果您不使用 django,这可能有点重量级。

UPDATE 2: I suppose as a last resort, you can also use jython and access the java caching system.更新 2:我想作为最后的手段,您还可以使用jython并访问 java 缓存系统。 This may be a little difficult to do if you've already got clients using CPython though.如果您已经让客户使用 CPython,这可能有点困难。

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.更新 3:对你有用可能有点晚了,但我以前的雇主使用ZODB 来做这种事情。 It's an actual database, but its read performance is fast enough to make it useful for caching.它是一个实际的数据库,但它的读取性能足够快,可以用于缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM