动态图像缓存
我有一个 CherryPy 应用程序,可以动态生成图像,这些图像会被多次重复使用,但每次都会生成。图像是从包含变量的查询字符串生成的,因此相同的查询字符串将始终返回相同的图像(直到我重写生成代码)并且图像不是特定于用户的。
我突然想到我应该积极缓存这些图像,但我不知道如何去做。我应该在 CherryPy 中记忆吗?我应该为 Apache 做类似的事情吗?完全是另一层吗?
I have a CherryPy app that dynamically generates images, and those images are re-used a lot but generated each time. The image is generated from a querystring containing the variables, so the same query string will always return the same image (until I rewrite the generation code) and the images are not user-specific.
It occurred to me that I should be aggressively caching those images, but I have no idea how I would go about doing that. Should I be memoizing in CherryPy? Should I do something like this for Apache? Another layer entirely?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的第一次尝试应该是使用 CherryPy 附带的 HTTP 缓存。请参阅 http://docs.cherrypy.org/dev/refman/lib/caching .html 了解概述。从这里开始,通过缓存超时平衡计算费用与 RAM 消耗通常是一个“简单”的问题。
Your first attempt should be to use the HTTP cache that comes with CherryPy. See http://docs.cherrypy.org/dev/refman/lib/caching.html for an overview. From there, it's usually a "simple" matter of balancing computational expense versus RAM consumption via cache timeouts.