This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

A simple filesystem cache for python.

Home Page, Documentation, & Repository

Introduction

Pyfscache (python filesystem cache) is a filesystem cache that is easy to use. The principal class is FSCache, instances of which may be used as decorators to create cached functions with very little coding overhead:

import pyfscache
cache_it = pyfscache.FSCache('some/cache/directory',
                             days=13, hours=4, minutes=2.5)
@cache_it
def cached_doit(a, b, c):
  return [a, b, c]

It’s that simple!

Now, every time the function cached_doit is called with a particular set of arguments, the cache cache_it is inspected to see if an identical call has been made before. If it has, then the return value is retrieved from the cache_it cache. If not, the return value is calculated with cached_doit, stored in the cache, and then returned.

Expiration

In the code above, the expiration for cache_it is set to 1,137,750 seconds (13 days, 4 hours, and 2.5 minutes), which means that every item created by cache_it has a lifetime of 1,137,750 seconds, beginning when the item is made (not beginning when cache_it is made). Values specifying lifetime may be provided with the keywords years, months, weeks, days, hours, minutes, and seconds. The lifetime is the total for all keywords.

If these optional keyword arguments are not included, then items added by the FSCache object never expire:

no_expiry_cache = pyfscache.FSCache('some/cache/directory')

Note

Several instances of FSCache objects can use the same cache directory. Each will honor the expirations of the items therein. Thus, it is possible to have a cache mixed with objects of many differening lifetimes, made by many instances of FSCache.

Works Like a Map

Instances of FSCache work like mapping objects, supporting item getting and setting:

>>> cache_it[('some', ['key'])] = {'some': 'value'}
>>> cache_it[('some', ['key'])]
{'some': 'value}

However, deletion with the del statement only works on memory. To erase an item in the cache directory, use expire:

>>> cache_it.get_loaded()
['LIlWpBZL68MBJaXouRjFBL3fzScyxh5q56hqSZ3DBK']
>>> del cache_it[('some', ['key'])]
>>> cache_it.get_loaded()
[]
>>> ('some', ['key']) in cache_it
True
>>> cache_it[('some', ['key'])]
{'some': 'value}
>>> cache_it.expire(('some', ['key']))
>>> ('some', ['key']) in cache_it
False

Decorators

What if you didn’t write the function you want to cache? Although their convenience is manifest in the example above, it is not necessary to use decorators:

import pyfscache
cache = pyfscache.FSCache('some/cache/directory',
                          days=13, hours=4, minutes=2.5)

def uncached_doit(a, b, c):
  return [a, b, c]

cached_doit = cache(uncached_doit)

Versatility

FSCache objects should work on the vast majority of python “callables”, including instance methods and even built-ins:

# a cached built-in
cached_list = cache_it(list)

# a cached instance method
class AClass(object):
  @cahe_it
  def some_cached_instance_method(self, a, r, g, s):
    return (a + r) / (g * s)

Note

The rule of thumb is that if python’s cPickle module can handle the expected arguments to the cached function, then so can pyfscache.

Release History

Release History

0.9.12

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.9.11

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.9.10

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.9.9

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.9.8

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pyfscache-0.9.12.tar.gz (79.4 kB) Copy SHA256 Checksum SHA256 Source Jan 29, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting