Perl, which is the best module to cache data for a web application?
I need some method to cache data fetched (or pre-fetched) from the internet in a web service written in Perl. Data collected is parsed to XML format. My goal is to decrease response time of my service to user requests.
I see there's a bunch of modules available: which is the most performing in terms of usability and efficiency (in that order of importance) ?
UPDATE:
I'm evaluating CHI, Cache, and Cache::Cache (which I suppose is 开发者_如何学Pythonquite outmoded...)
I'm in a mod_perl2 Linux environment: in this case, does a memory cache make any sense?
CHI
is a good base, and can do most caching you are likely to need, with the back-end chosen according to your need. We used to use Cache::Cache
, and on occasion even Memoize
, but CHI
appeared best in the end, and has certainly superseded Cache::Cache
.
Now for the caching back-end system. This will depend a lot on your web setup, and even on your operating system and hardware. If you have a lot of memory, and/or are running a small number of server processes, a memory-based cache is solid and easy. If you are running many processes and still have decent memory, you probably want a shared memory cache (and this will work fine on Linux and UNIX systems, but might not be supportable on Windows). If you have less memory, a file-based cache will work, but it'll be slower.
However, if you are only prefetching, you might just as well use a database. And even if the caching is mainly there to avoid network requests, an SQL database will still provide the performance improvement you need. There's also a CHI
driver for that at: CHI::Driver::DBI
. Most databases do very decent caching anyway.
UPDATE:
Cache
and Cache::Cache
are both pretty old. CHI
has been designed to replace Cache::Cache
. Of these, CHI
is definitely the best.
Yes, even in mod_perl, a memory cache can be useful, but you can't afford it to become too large. mod_perl embeds Perl in the server processes, so each server process will have its own cache. This reduces effectiveness, but if you have a small number of things to cache, and they are used often, it is still worth using.
Assuming you're on a UNIX-type system, a shared memory cache or a database cache will likely be your best bet, depending on how many things you are likely to need to cache, and their size. If your cache will become huge, and if network latency is the main part of the problem, a database cache backend will be fine. If the cache will always be relatively small, memory or shared memory should suit.
精彩评论