Skip to main content

Persistent caching decorator

Project description

filecache

filecache is a decorator which saves the return value of functions even
after the interpreter dies. For example this is useful on functions that download
and parse webpages. All you need to do is specify how long
the return values should be cached (use seconds, like time.sleep).

USAGE:

from filecache import filecache

@filecache(24 * 60 * 60)
def time_consuming_function(args):
# etc


NOTE: All arguments of the decorated function and the return value need to be
picklable for this to work.

NOTE: The cache isn't automatically cleaned, it is only overwritten. If your
function can receive many different arguments that rarely repeat, your
cache may forever grow. One day I might add a feature that once in every
100 calls scans the db for outdated stuff and erases.

NOTE: This is less useful on methods of a class because the instance (self)
is cached, and if the instance isn't the same, the cache isn't used. This
makes sense because class methods are affected by changes in whatever
is attached to self.

Tested on python 2.7 and 3.1

License: BSD, do what you wish with this. Could be awesome to hear if you found
it useful and/or you have suggestions. ubershmekel at gmail

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

filecache-0.69.zip (3.7 kB view details)

Uploaded Source

File details

Details for the file filecache-0.69.zip.

File metadata

  • Download URL: filecache-0.69.zip
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for filecache-0.69.zip
Algorithm Hash digest
SHA256 17ec0d7bdb68f059e97b393a6290d962613217f7d106e977efe38c1958c4ab62
MD5 cf08a32451ec191d6ea68b4854407f07
BLAKE2b-256 6beeab4889f722993f61d88fee3d07cd424ed7b28245e00be5b3a9aa45e12ddf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page