A simple, persistent key/value cache with no dependencies.
Project description
pepper-cache
A simple, persistent key/value cache with no dependencies.
Installation
$ pip install pepper-cache
API
create_cache
- Creates a Cache instance.name: str
- The name of the cache instancepath: str
- The directory in which to store cache files relative to<HOME>/.cache
serializer: "pickle"|"json" = "pickle"
- The serializer to use when writing values to the disk, defaults to "pickle"
my_cache = create_cache("my cache", "my_app/my_cache", serializer="json")
get_cache
- Retrieves a Cache instance.name: str
- The name of the cache instance to retrieve
my_cache = get_cache("my cache")
my_cache2 = get_cache("my cache 2") # raises a KeyError
Cache.set
- Sets an item in the cache. Existing items will be overwritten.key: str
- The name of the cached valuevalue: Any
- The value to storettl: int = 0
- The time in milliseconds that the value should remain in the cache or 0 for indefinitely, defaults to0
cache.set("my key", my_value) # stored indefinitely
cache.set("my key", my_value, ttl=1000) # stored for one second
Cache.get
- Retrieves a value from the cache if it exists and has not expired.key: str
- The key of the cache item to retrievedefault: Any
- The default value to return if the value is not stored
my_value = cache.get("my key 2") # returns None if the value is not stored or has expired. Consider checking if the item exists below
my_value2 = cache.get("my key 2", default="now has a value")
Cache.has
- ReturnsTrue
if an item exists in the cache by its key.key: str
- The key of the cache item to check the existence of
if not cache.has("my key 2"):
cache.set("my key 2", "has a value!")
Cache.delete
- Deletes an item from the cache if it exists.key: str
- The key of the cache item to delete from the cache
cache.delete("my key 2"):
cache.get("my key 2") # None
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
pepper-cache-1.0.0.tar.gz
(4.6 kB
view hashes)
Built Distribution
Close
Hashes for pepper_cache-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8724a00b853092bbb66c9d91bdeeed1a137eed39f27777e76884de4a6c21de89 |
|
MD5 | db584b5adc55fd7a8352716b37889f72 |
|
BLAKE2b-256 | 37ed4de26b7452aedd8b85e360af5f06069c55b801ad5e9286255e7276a1c750 |