ddb-cache


Nameddb-cache JSON
Version 0.5.30 PyPI version JSON
download
home_page
SummaryA simple interface for caching items in DynamoDB
upload_time2022-07-03 01:38:19
maintainer
docs_urlNone
author
requires_python>=3.9
licenseGPL-3.0-or-later
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ddbcache

A simple interface for caching items in DynamoDB

[![Release](https://github.com/samarthj/py-ddbcache/actions/workflows/release.yml/badge.svg)](https://github.com/samarthj/py-ddbcache/actions/workflows/release.yml)
[![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/samarthj/py-ddbcache?sort=semver)](https://github.com/samarthj/py-ddbcache/releases)
[![PyPI](https://img.shields.io/pypi/v/ddb-cache)](https://pypi.org/project/ddb-cache/)

[![Build](https://github.com/samarthj/py-ddbcache/actions/workflows/build_matrix.yml/badge.svg)](https://github.com/samarthj/py-ddbcache/actions/workflows/build_matrix.yml)
[![codecov](https://codecov.io/gh/samarthj/py-ddbcache/branch/main/graph/badge.svg?token=9VCCD1BDNY)](https://codecov.io/gh/samarthj/py-ddbcache)

[![Total alerts](https://img.shields.io/lgtm/alerts/g/samarthj/py-ddbcache.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/samarthj/py-ddbcache/alerts/)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/samarthj/py-ddbcache.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/samarthj/py-ddbcache/context:python)

[![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)](https://pdm.fming.dev)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)

## Example Usage

Samples can be found here in the [tests](https://github.com/samarthj/py-ddbcache/blob/main/tests/test_db.py)

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:

```python
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
```


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "ddb-cache",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "Sam <dev@samarthj.com>",
    "download_url": "https://files.pythonhosted.org/packages/7c/d4/156a434b13004cdd05ea4dd1a443eabc00049686a4dededcf06992d65886/ddb-cache-0.5.30.tar.gz",
    "platform": null,
    "description": "# ddbcache\n\nA simple interface for caching items in DynamoDB\n\n[![Release](https://github.com/samarthj/py-ddbcache/actions/workflows/release.yml/badge.svg)](https://github.com/samarthj/py-ddbcache/actions/workflows/release.yml)\n[![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/samarthj/py-ddbcache?sort=semver)](https://github.com/samarthj/py-ddbcache/releases)\n[![PyPI](https://img.shields.io/pypi/v/ddb-cache)](https://pypi.org/project/ddb-cache/)\n\n[![Build](https://github.com/samarthj/py-ddbcache/actions/workflows/build_matrix.yml/badge.svg)](https://github.com/samarthj/py-ddbcache/actions/workflows/build_matrix.yml)\n[![codecov](https://codecov.io/gh/samarthj/py-ddbcache/branch/main/graph/badge.svg?token=9VCCD1BDNY)](https://codecov.io/gh/samarthj/py-ddbcache)\n\n[![Total alerts](https://img.shields.io/lgtm/alerts/g/samarthj/py-ddbcache.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/samarthj/py-ddbcache/alerts/)\n[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/samarthj/py-ddbcache.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/samarthj/py-ddbcache/context:python)\n\n[![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)](https://pdm.fming.dev)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n\n## Example Usage\n\nSamples can be found here in the [tests](https://github.com/samarthj/py-ddbcache/blob/main/tests/test_db.py)\n\nThe library can also be used for crud operations since it implement `get`, `put`, `update`, `delete`, `scan` and `query`. Along with `create_backup`.\n\nBasic usage is as given below:\n\n```python\ndef test_put_cache(ddb_cache: DDBCache):\n    data = randint(1, 100)  # noqa: S311\n    ddb_cache.put_cache({\"id\": \"test_put_cache\", \"data\": data})\n    item = ddb_cache.get_item({\"id\": \"test_put_cache\"})\n    assert item\n    assert item[\"id\"] == \"test_put_cache\"\n    assert item[\"data\"] == data\n    assert item[\"ttl\"]\n\n\ndef test_put_cache_no_ttl(ddb_cache: DDBCache):\n    data = randint(1, 100)  # noqa: S311\n    ddb_cache.put_cache({\"id\": \"test_put_cache\", \"data\": data}, with_ttl=False)\n    item = ddb_cache.get_item({\"id\": \"test_put_cache\"})\n    assert item\n    assert item[\"id\"] == \"test_put_cache\"\n    assert item[\"data\"] == data\n    with pytest.raises(KeyError):\n        item[\"ttl\"]\n\n\ndef test_fetch_cache(ddb_cache: DDBCache, init_cache):\n    item = ddb_cache.get_item({\"id\": \"test_fetch_cache\"})\n    assert item\n    assert item[\"id\"] == \"test_fetch_cache\"\n    assert item[\"data\"] == \"test_fetch_cache\"\n    ttl = item[\"ttl\"]\n    assert ttl\n    sleep(1)\n    item = ddb_cache.fetch_cache({\"id\": \"test_fetch_cache\"})\n    assert item\n    assert item[\"id\"] == \"test_fetch_cache\"\n    assert item[\"data\"] == \"test_fetch_cache\"\n    with pytest.raises(KeyError):\n        item[\"ttl\"]\n    item = ddb_cache.get_item({\"id\": \"test_fetch_cache\"})\n    assert item\n    assert item[\"id\"] == \"test_fetch_cache\"\n    assert item[\"data\"] == \"test_fetch_cache\"\n    ttl2 = item[\"ttl\"]\n    assert ttl2\n    assert ttl != ttl2\n\n\ndef test_fetch_cache_no_ttl_update(ddb_cache: DDBCache, init_cache):\n    item = ddb_cache.get_item({\"id\": \"test_fetch_cache\"})\n    assert item\n    assert item[\"id\"] == \"test_fetch_cache\"\n    assert item[\"data\"] == \"test_fetch_cache\"\n    ttl = item[\"ttl\"]\n    assert ttl\n    item = ddb_cache.fetch_cache({\"id\": \"test_fetch_cache\"}, with_ttl=False)\n    assert item\n    assert item[\"id\"] == \"test_fetch_cache\"\n    assert item[\"data\"] == \"test_fetch_cache\"\n    with pytest.raises(KeyError):\n        item[\"ttl\"]\n    item = ddb_cache.get_item({\"id\": \"test_fetch_cache\"})\n    assert item\n    assert item[\"id\"] == \"test_fetch_cache\"\n    assert item[\"data\"] == \"test_fetch_cache\"\n    ttl2 = item[\"ttl\"]\n    assert ttl2\n    assert ttl == ttl2\n```\n\n",
    "bugtrack_url": null,
    "license": "GPL-3.0-or-later",
    "summary": "A simple interface for caching items in DynamoDB",
    "version": "0.5.30",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "db0022a4a675290d8ebe57ad24d30ac4",
                "sha256": "c33d491dc814dd2a1c2434b27e73a6293fa1fee276a1a5f7561024317dcd266a"
            },
            "downloads": -1,
            "filename": "ddb_cache-0.5.30-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "db0022a4a675290d8ebe57ad24d30ac4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 15707,
            "upload_time": "2022-07-03T01:38:18",
            "upload_time_iso_8601": "2022-07-03T01:38:18.184280Z",
            "url": "https://files.pythonhosted.org/packages/44/76/90f7fe62908e0a3e93fe1bec33bd6720a632e833e8c72104aa6ce3981449/ddb_cache-0.5.30-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "d5d561e9a43e19ea2be9adc5d6f8db8e",
                "sha256": "cc61f6b4b22b48ece16af653c3f012439fb5a8073daf564e41b3f3e87950247f"
            },
            "downloads": -1,
            "filename": "ddb-cache-0.5.30.tar.gz",
            "has_sig": false,
            "md5_digest": "d5d561e9a43e19ea2be9adc5d6f8db8e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 18050,
            "upload_time": "2022-07-03T01:38:19",
            "upload_time_iso_8601": "2022-07-03T01:38:19.917789Z",
            "url": "https://files.pythonhosted.org/packages/7c/d4/156a434b13004cdd05ea4dd1a443eabc00049686a4dededcf06992d65886/ddb-cache-0.5.30.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-07-03 01:38:19",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "ddb-cache"
}
        
Elapsed time: 0.41943s