Welcome to fcache¶
fcache is a dictionary-like, file-based cache module for Python. This is fcache’s documentation. It covers installation, a tutorial, and the API reference.
Getting Started¶
Let’s create a file cache:
>>> from fcache.cache import FileCache
>>> mycache = FileCache('appname')
You can use the cache just like a dict
:
>>> mycache['foo'] = 'value'
>>> mycache['foo']
'value'
>>> mycache['bar'] = 'blah'
>>> list(mycache)
['foo', 'bar']
>>> del mycache['bar']
By default, the cache object stores changes in a buffer that needs to be explicitly synced with the cache’s files:
>>> mycache.sync()
>>> # closing a cache also syncs it:
... mycache.close()
If you want the cache to automatically write changes to disk everytime you
add/modify values, open the cache and append 's'
to the optional flag
argument:
>>> mycache = FileCache('appname', flag='cs')
The 'c'
means that the object will open a cache if it exists, but will
create a new one if no cache is found. The 's'
means that the cache is
opened in sync mode. All changes are immediately written to disk.
Using fcache with a Shelf
¶
Python’s Shelf
class provides a persistent dictionary-like
object. Shelves normally use the dbm
module as a backend. You can use easily use
fcache as a shelf’s backend if needed. Because shelves already serialize data,
you’ll need to tell fcache not to serialize the data:
>>> mycache = FileCache('appname', serialize=False)
>>> myshelf = Shelf(mycache)
That’s it! You can use the Shelf
just like you normally
would.
Documentation Contents¶
- Installation
- API
- Contributing
- Credits
- Change Log
- v.0.5.2 (2024-02-22)
- v.0.5.1 (2023-06-28)
- v.0.5.0 (2023-03-19)
- v.0.4.7 (2017-03-11)
- v.0.4.6 (2017-01-30)
- v.0.4.5 (2015-10-21)
- v.0.4.4 (2014-03-19)
- v.0.4.3 (2014-03-13)
- v.0.4.2 (2014-03-01)
- v.0.4.1 (2014-01-03)
- v.0.4 (2014-01-02)
- v.0.3.1 (2013-04-19)
- v.0.3 (2013-01-03)
- v.0.2.1 (2012-12-31)
- v0.2 (2012-12-31)
- v0.1 (2012-12-30)