https://github.com/im-cloud-spain-connectors/python-cache-postgresql-adapter
PostgreSQL implementation of the Cache Interface for Python.
https://github.com/im-cloud-spain-connectors/python-cache-postgresql-adapter
adapter cache component postgresql python
Last synced: 12 months ago
JSON representation
PostgreSQL implementation of the Cache Interface for Python.
- Host: GitHub
- URL: https://github.com/im-cloud-spain-connectors/python-cache-postgresql-adapter
- Owner: IM-Cloud-Spain-Connectors
- License: apache-2.0
- Created: 2023-02-14T10:25:25.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-06-27T11:00:25.000Z (about 3 years ago)
- Last Synced: 2025-04-15T17:47:10.220Z (about 1 year ago)
- Topics: adapter, cache, component, postgresql, python
- Language: Python
- Homepage:
- Size: 22.5 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Python Cache PostgreSQL Adapter
[](https://github.com/othercodes/python-cache-postgresql-adapter/actions/workflows/test.yml)
Provides a PostgreSQL implementation of the Cache Interface for Python.
## Installation
The easiest way to install the Cache PostgreSQL Adapter is to get the latest version from PyPI:
```bash
# using poetry
poetry add rndi-cache-postgresql-adapter
# using pip
pip install rndi-cache-postgresql-adapter
```
## The Contract
The used interface is `rndi.cache.contracts.Cache`.
## The Adapter
Just initialize the class you want and use the public methods:
```python
from rndi.cache.contracts import Cache
from rndi.cache.adapters.postgresql.adapter import PostgreSQLCacheAdapter
def some_process_that_requires_cache(cache: Cache):
# retrieve the data from cache, ir the key is not cached yet and the default
# value is a callable the cache will use it to compute and cache the value
user = cache.get('user-id', lambda: db_get_user('user-id'))
print(user)
# inject the desired cache adapter.
cache = PostgreSQLCacheAdapter(
'localhost',
'database_name',
'username',
'password',
ttl=900, # optional
port=5432 # optional
)
some_process_that_requires_cache(cache)
```