A simple interface for caching items in DynamoDB
Project description
ddb-cache
A simple interface for caching items in DynamoDB
Example Usage
Samples can be found here in the tests
The library can also be used for crud operations since it implement get, put, update, delete, scan and query. Along with create_backup.
Basic usage is as given below:
def test_put_cache(ddb_cache: DDBCache):
data = randint(1, 100) # noqa: S311
ddb_cache.put_cache({"id": "test_put_cache", "data": data})
item = ddb_cache.get_item({"id": "test_put_cache"})
assert item
assert item["id"] == "test_put_cache"
assert item["data"] == data
assert item["ttl"]
def test_put_cache_no_ttl(ddb_cache: DDBCache):
data = randint(1, 100) # noqa: S311
ddb_cache.put_cache({"id": "test_put_cache", "data": data}, with_ttl=False)
item = ddb_cache.get_item({"id": "test_put_cache"})
assert item
assert item["id"] == "test_put_cache"
assert item["data"] == data
with pytest.raises(KeyError):
item["ttl"]
def test_fetch_cache(ddb_cache: DDBCache, init_cache):
item = ddb_cache.get_item({"id": "test_fetch_cache"})
assert item
assert item["id"] == "test_fetch_cache"
assert item["data"] == "test_fetch_cache"
ttl = item["ttl"]
assert ttl
sleep(1)
item = ddb_cache.fetch_cache({"id": "test_fetch_cache"})
assert item
assert item["id"] == "test_fetch_cache"
assert item["data"] == "test_fetch_cache"
with pytest.raises(KeyError):
item["ttl"]
item = ddb_cache.get_item({"id": "test_fetch_cache"})
assert item
assert item["id"] == "test_fetch_cache"
assert item["data"] == "test_fetch_cache"
ttl2 = item["ttl"]
assert ttl2
assert ttl != ttl2
def test_fetch_cache_no_ttl_update(ddb_cache: DDBCache, init_cache):
item = ddb_cache.get_item({"id": "test_fetch_cache"})
assert item
assert item["id"] == "test_fetch_cache"
assert item["data"] == "test_fetch_cache"
ttl = item["ttl"]
assert ttl
item = ddb_cache.fetch_cache({"id": "test_fetch_cache"}, with_ttl=False)
assert item
assert item["id"] == "test_fetch_cache"
assert item["data"] == "test_fetch_cache"
with pytest.raises(KeyError):
item["ttl"]
item = ddb_cache.get_item({"id": "test_fetch_cache"})
assert item
assert item["id"] == "test_fetch_cache"
assert item["data"] == "test_fetch_cache"
ttl2 = item["ttl"]
assert ttl2
assert ttl == ttl2
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ddb-cache-0.6.0.tar.gz.
File metadata
- Download URL: ddb-cache-0.6.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.1.4 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79a4b58690209b73703175e4389adc43294016430934645ae949738a970f7e2e
|
|
| MD5 |
e6f7d2b5d1218c18b5f5226a717aab12
|
|
| BLAKE2b-256 |
731322fe7afc4c0024266dd7f40053df696cb084ca5afa94fcd649b255ea2578
|
File details
Details for the file ddb_cache-0.6.0-py3-none-any.whl.
File metadata
- Download URL: ddb_cache-0.6.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.1.4 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29b35c32b671274f112b2597553e5f78afd980c79cc4723854828af2bbba33c2
|
|
| MD5 |
d13afc0d91174c5619f871d01801d18b
|
|
| BLAKE2b-256 |
63b29b999b265be9a5a2381904285a24a1c4119767fdb32b40b5dabd404c5fc6
|