A simple interface for caching items in DynamoDB
Project description
ddbcache
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
ddb-cache-0.5.23.tar.gz
(18.1 kB
view hashes)
Built Distribution
ddb_cache-0.5.23-py3-none-any.whl
(15.7 kB
view hashes)
Close
Hashes for ddb_cache-0.5.23-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f73be4a7ff5311f81d9f6e6ee16eade30a6de1f7eaeb81f59ce8a4e8e30c8a6 |
|
MD5 | 007c4f6151fadc0ca4b086a647236d5c |
|
BLAKE2b-256 | 28b9aa1d40478a997498eaece5da3c52e6948f441571a298577eb8e48b6e9adc |