Cache system for python
Project description
SimpleCache
Usage
from SimpleCache2 import simple_cache
from SimpleCache2.FileCache import FileCache
from SimpleCache2.MemoryCache import MemoryCache
from SimpleCache2.Settings import Settings
# save cache in python variable
memory = MemoryCache()
# save cache in one json file
settings = Settings(settings_file="path/to/test.json")
# save cache in many binary files
cache = FileCache(cache_dir=None)
# Usage as decorator
@simple_cache(cache, ttl=10, key_prefix="test_")
def testFunc(name):
return f"hello world {name}"
# Usage as callback
cache.call(["cache key can be any value"], 10, testFunc, "Bob")
# Usage as functional
cache.set("key", "value") # self
cache.get("key") # value
cache.exist("key") # bool
cache.delete("key") # bool
cache.clearOld() # bool
Api
You can write you self cache class:
from SimpleCache2.CacheSystem import CacheSystem
class MyCacheClass(CacheSystem):
def exist(self, key: any) -> bool:
pass
def get(self, key: any) -> any:
pass
def set(self, key: any, value: object, ttl: int = 0) -> object:
return self
pass
def delete(self, key: any) -> bool:
pass
def clearOld(self):
pass
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
SimpleCache2-1.2.1.tar.gz
(3.9 kB
view details)
Built Distribution
File details
Details for the file SimpleCache2-1.2.1.tar.gz
.
File metadata
- Download URL: SimpleCache2-1.2.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1f01f68a7b7e586699a6e0c7dbcb93975ff2328640b41d5bdc45fa4bebd8802 |
|
MD5 | fff23fe9d3e615a279b30a17622171af |
|
BLAKE2b-256 | ced2a31c5e56cba70176b5a8a68c740f0b294b8819ea8bc58b1ac2a51527bdc0 |
File details
Details for the file SimpleCache2-1.2.1-py3-none-any.whl
.
File metadata
- Download URL: SimpleCache2-1.2.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b77bf235b8974e084a467953e6b1f5b2c52139c4918bb3f79eb94a8d673d9cf |
|
MD5 | 484d56c669771ba80832e3f9406bfb81 |
|
BLAKE2b-256 | 6e33e053a3bd7f8d87a502695e93ae8f5b78a7cbcd72038524b77ac3be3683ea |