Name | cacheia JSON |
Version |
1.0.0.post3
JSON |
| download |
home_page | None |
Summary | Cache library that allows invalidation and other shenanigans |
upload_time | 2024-07-24 17:50:05 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.12 |
license | None |
keywords |
cache
core
lib
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Cacheia
Cacheia has all the core functionality for the "cacheia" package. It exposes a simple interface for multiple cache providers with added features like cache invalidation and cache expiration.
## Installation
Install core with "schemas" optional to download schemas dependency:
```bash
pip install -e ./core[schemas]
```
## Code
Cacheia mainly exposes one interface to interact with all backends and some custom exceptions:
- Cacheia: The main interface to interact with all backends.
- InvalidSettings: Exception raised when an invalid settings class type is passed to `Cacheia.setup` method.
- KeyAlreadyExists: Exception raised when a key already exists in the cache and the user tries to set it again.
- decorator: Module that exposes a decorator to cache function calls.
## Examples
To create a new cache:
```python
from cacheia import Cacheia
from cacheia_schemas import CachedValue
Cacheia.setup()
cache = Cacheia.get()
instance = CachedValue(key="key", value="value")
cache.cache(instance=instance)
```
---
To get all cached values:
```python
from cacheia import Cacheia
Cacheia.setup()
cache = Cacheia.get()
for value in cache.get():
print(value)
```
---
To get a value from the cache:
```python
from cacheia import Cacheia
Cacheia.setup()
cache = Cacheia.get()
cached_value = cache.get_key("key")
print(cached_value)
```
---
To flush all values:
```python
from cacheia import Cacheia
Cacheia.setup()
cache = Cacheia.get()
result = cache.flush()
print(result.deleted_count)
```
---
To flush some values:
```python
from datetime import datetime
from cacheia import Cacheia
Cacheia.setup()
cache = Cacheia.get()
now = datetime.now().timestamp()
result = cache.flush(expires_range=(now - 100, now + 100))
print(result.deleted_count)
```
---
To flush a single key:
```python
from cacheia import Cacheia
Cacheia.setup()
cache = Cacheia.get()
result = cache.flush_key(key="key")
print(result.deleted_count)
```
Raw data
{
"_id": null,
"home_page": null,
"name": "cacheia",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "cache, core, lib",
"author": null,
"author_email": "TeiaLabs <contato@teialabs.com>",
"download_url": "https://files.pythonhosted.org/packages/51/9f/5b5fffd2f5fcc9f982088ce0f8ca3ee7a63ae45e9ae6dbec06068aa9f6a7/cacheia-1.0.0.post3.tar.gz",
"platform": null,
"description": "# Cacheia\n\nCacheia has all the core functionality for the \"cacheia\" package. It exposes a simple interface for multiple cache providers with added features like cache invalidation and cache expiration.\n\n## Installation\n\nInstall core with \"schemas\" optional to download schemas dependency:\n\n```bash\npip install -e ./core[schemas]\n```\n\n## Code\n\nCacheia mainly exposes one interface to interact with all backends and some custom exceptions:\n\n- Cacheia: The main interface to interact with all backends.\n- InvalidSettings: Exception raised when an invalid settings class type is passed to `Cacheia.setup` method.\n- KeyAlreadyExists: Exception raised when a key already exists in the cache and the user tries to set it again.\n- decorator: Module that exposes a decorator to cache function calls.\n\n## Examples\n\nTo create a new cache:\n\n```python\nfrom cacheia import Cacheia\nfrom cacheia_schemas import CachedValue\n\n\nCacheia.setup()\ncache = Cacheia.get()\ninstance = CachedValue(key=\"key\", value=\"value\")\ncache.cache(instance=instance)\n```\n\n---\n\nTo get all cached values:\n\n```python\nfrom cacheia import Cacheia\n\n\nCacheia.setup()\ncache = Cacheia.get()\nfor value in cache.get():\n print(value)\n```\n\n---\n\nTo get a value from the cache:\n\n```python\nfrom cacheia import Cacheia\n\n\nCacheia.setup()\ncache = Cacheia.get()\ncached_value = cache.get_key(\"key\")\nprint(cached_value)\n```\n\n---\n\nTo flush all values:\n\n```python\nfrom cacheia import Cacheia\n\n\nCacheia.setup()\ncache = Cacheia.get()\nresult = cache.flush()\nprint(result.deleted_count)\n```\n\n---\n\nTo flush some values:\n\n```python\nfrom datetime import datetime\nfrom cacheia import Cacheia\n\n\nCacheia.setup()\ncache = Cacheia.get()\n\nnow = datetime.now().timestamp()\nresult = cache.flush(expires_range=(now - 100, now + 100))\nprint(result.deleted_count)\n```\n\n---\n\nTo flush a single key:\n\n```python\nfrom cacheia import Cacheia\n\n\nCacheia.setup()\ncache = Cacheia.get()\n\nresult = cache.flush_key(key=\"key\")\nprint(result.deleted_count)\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Cache library that allows invalidation and other shenanigans",
"version": "1.0.0.post3",
"project_urls": null,
"split_keywords": [
"cache",
" core",
" lib"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b441533660481096881fa94d9ecb646a4aa1d7916052431cadfd5ce375394b3a",
"md5": "62b2dd9fa9f0f51326ff46482ae8b91f",
"sha256": "a62c785ef1f141cc601b45f700886c027b413c099c90c5123ff738013ece0f13"
},
"downloads": -1,
"filename": "cacheia-1.0.0.post3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "62b2dd9fa9f0f51326ff46482ae8b91f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 6479,
"upload_time": "2024-07-24T17:50:04",
"upload_time_iso_8601": "2024-07-24T17:50:04.530895Z",
"url": "https://files.pythonhosted.org/packages/b4/41/533660481096881fa94d9ecb646a4aa1d7916052431cadfd5ce375394b3a/cacheia-1.0.0.post3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "519f5b5fffd2f5fcc9f982088ce0f8ca3ee7a63ae45e9ae6dbec06068aa9f6a7",
"md5": "04247c7903d4cebc6be73a3489ef754f",
"sha256": "89d39006bd0c34200040841c64522f992456417c6e5ef4a81b555fa78e81965a"
},
"downloads": -1,
"filename": "cacheia-1.0.0.post3.tar.gz",
"has_sig": false,
"md5_digest": "04247c7903d4cebc6be73a3489ef754f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 7243,
"upload_time": "2024-07-24T17:50:05",
"upload_time_iso_8601": "2024-07-24T17:50:05.961188Z",
"url": "https://files.pythonhosted.org/packages/51/9f/5b5fffd2f5fcc9f982088ce0f8ca3ee7a63ae45e9ae6dbec06068aa9f6a7/cacheia-1.0.0.post3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-24 17:50:05",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "cacheia"
}