cachepot


Namecachepot JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/kitsuyui/cachepot
SummaryYet another Python cache library
upload_time2024-10-15 16:30:34
maintainerNone
docs_urlNone
authorYui Kitsu
requires_python>=3.9
licenseBSD-3-Clause
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cachepot

[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cachepot.svg)](https://pypi.python.org/pypi/cachepot/)
[![PyPI](https://img.shields.io/pypi/v/cachepot.svg)](https://pypi.python.org/pypi/cachepot/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/cachepot.svg)](https://pypi.python.org/pypi/cachepot/)
[![Lint and Test Python](https://github.com/kitsuyui/cachepot/actions/workflows/python-test.yml/badge.svg)](https://github.com/kitsuyui/cachepot/actions/workflows/python-test.yml)
[![codecov](https://codecov.io/gh/kitsuyui/cachepot/branch/main/graph/badge.svg?token=mdzEJ8cwcB)](https://codecov.io/gh/kitsuyui/cachepot)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)

Yet another Python cache library. This has Python 3 typing hints.

## Installation

```
$ pip install cachepot
```

## Usage

```python
>>> from cachepot.store import CacheStore
>>> from cachepot.backend.filesystem import FileSystemCacheBackend
>>> from cachepot.serializer.pickle import PickleSerializer
>>> store = CacheStore(
...     namespace='testing',
...     key_serializer=PickleSerializer(),
...     value_serializer=PickleSerializer(),
...     backend=FileSystemCacheBackend('/tmp'),
...     default_expire_seconds=3600,
... )
>>> store.put({'some': 'key'}, {'some': 'value'})
>>> store.get({'some': 'key'})
{'some': 'value'}
>>> store.put({'some': 'short expiring key'}, {'some': 'value'}, expire_seconds=10)
```

### Proxy method

```python
result = store.proxy(some_func)(some_args)
```

is the equivalent of

```python
result = store.get(some_arg)
if result is None:
    result = some_func(some_args)
    store.set(result)
```

In short, this works as proxy. This helps to make codes straight forward.
proxy method can be passed two arguments `cache_key` and `expire_seconds`.

## Core idea

Serializers convert python objects into bytes.
Backends save/load bytes.
So serializers and backends are independent.
CacheStore is the facade of them.

- Python3 typing supports
- namespaces
- Proxy method

## Features

### Serializers

- str ... [cachepot.serializer.str.StringSerializer](https://github.com/kitsuyui/cachepot/blob/master/cachepot/serializer/str.py)
- [pickle](https://docs.python.org/3/library/pickle.html) ... [cachepot.serializer.pickle.PickleSerializer](https://github.com/kitsuyui/cachepot/blob/master/cachepot/serializer/pickle.py)
- [JSON](https://tools.ietf.org/html/rfc8259) ... [cachepot.serializer.json.JSONSerializer](https://github.com/kitsuyui/cachepot/blob/master/cachepot/serializer/json.py)

And more serializers you can define.

### Backends

- Save to files ... [cachepot.backend.filesystem.FileSystemCacheBackend](https://github.com/kitsuyui/cachepot/blob/master/cachepot/backend/filesystem.py)
- Save to SQLite3 DB records ... [cachepot.backend.sqlite.SQLiteCacheBackend](https://github.com/kitsuyui/cachepot/blob/master/cachepot/backend/sqlite.py)
- Save to Redis DB ... [cachepot.backend.redis.RedisCacheBackend](https://github.com/kitsuyui/cachepot/blob/master/cachepot/backend/redis.py)

Of course you can define own backend.

## Development

You can install requirements with poetry.

```shell
$ poetry install
```

### Test

```shell
$ poetry poe check  # lint and type check
$ poetry poe test  # run tests
```

# LICENSE

The 3-Clause BSD License. See also LICENSE file.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kitsuyui/cachepot",
    "name": "cachepot",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Yui Kitsu",
    "author_email": "kitsuyui+github@kitsuyui.com",
    "download_url": "https://files.pythonhosted.org/packages/fa/88/db63d9780847639cd52c067ace4823d36466b508b93bb5447b5b47e2cf7a/cachepot-0.4.0.tar.gz",
    "platform": null,
    "description": "# cachepot\n\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cachepot.svg)](https://pypi.python.org/pypi/cachepot/)\n[![PyPI](https://img.shields.io/pypi/v/cachepot.svg)](https://pypi.python.org/pypi/cachepot/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/cachepot.svg)](https://pypi.python.org/pypi/cachepot/)\n[![Lint and Test Python](https://github.com/kitsuyui/cachepot/actions/workflows/python-test.yml/badge.svg)](https://github.com/kitsuyui/cachepot/actions/workflows/python-test.yml)\n[![codecov](https://codecov.io/gh/kitsuyui/cachepot/branch/main/graph/badge.svg?token=mdzEJ8cwcB)](https://codecov.io/gh/kitsuyui/cachepot)\n[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)\n\nYet another Python cache library. This has Python 3 typing hints.\n\n## Installation\n\n```\n$ pip install cachepot\n```\n\n## Usage\n\n```python\n>>> from cachepot.store import CacheStore\n>>> from cachepot.backend.filesystem import FileSystemCacheBackend\n>>> from cachepot.serializer.pickle import PickleSerializer\n>>> store = CacheStore(\n...     namespace='testing',\n...     key_serializer=PickleSerializer(),\n...     value_serializer=PickleSerializer(),\n...     backend=FileSystemCacheBackend('/tmp'),\n...     default_expire_seconds=3600,\n... )\n>>> store.put({'some': 'key'}, {'some': 'value'})\n>>> store.get({'some': 'key'})\n{'some': 'value'}\n>>> store.put({'some': 'short expiring key'}, {'some': 'value'}, expire_seconds=10)\n```\n\n### Proxy method\n\n```python\nresult = store.proxy(some_func)(some_args)\n```\n\nis the equivalent of\n\n```python\nresult = store.get(some_arg)\nif result is None:\n    result = some_func(some_args)\n    store.set(result)\n```\n\nIn short, this works as proxy. This helps to make codes straight forward.\nproxy method can be passed two arguments `cache_key` and `expire_seconds`.\n\n## Core idea\n\nSerializers convert python objects into bytes.\nBackends save/load bytes.\nSo serializers and backends are independent.\nCacheStore is the facade of them.\n\n- Python3 typing supports\n- namespaces\n- Proxy method\n\n## Features\n\n### Serializers\n\n- str ... [cachepot.serializer.str.StringSerializer](https://github.com/kitsuyui/cachepot/blob/master/cachepot/serializer/str.py)\n- [pickle](https://docs.python.org/3/library/pickle.html) ... [cachepot.serializer.pickle.PickleSerializer](https://github.com/kitsuyui/cachepot/blob/master/cachepot/serializer/pickle.py)\n- [JSON](https://tools.ietf.org/html/rfc8259) ... [cachepot.serializer.json.JSONSerializer](https://github.com/kitsuyui/cachepot/blob/master/cachepot/serializer/json.py)\n\nAnd more serializers you can define.\n\n### Backends\n\n- Save to files ... [cachepot.backend.filesystem.FileSystemCacheBackend](https://github.com/kitsuyui/cachepot/blob/master/cachepot/backend/filesystem.py)\n- Save to SQLite3 DB records ... [cachepot.backend.sqlite.SQLiteCacheBackend](https://github.com/kitsuyui/cachepot/blob/master/cachepot/backend/sqlite.py)\n- Save to Redis DB ... [cachepot.backend.redis.RedisCacheBackend](https://github.com/kitsuyui/cachepot/blob/master/cachepot/backend/redis.py)\n\nOf course you can define own backend.\n\n## Development\n\nYou can install requirements with poetry.\n\n```shell\n$ poetry install\n```\n\n### Test\n\n```shell\n$ poetry poe check  # lint and type check\n$ poetry poe test  # run tests\n```\n\n# LICENSE\n\nThe 3-Clause BSD License. See also LICENSE file.\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Yet another Python cache library",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/kitsuyui/cachepot"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2a890e7fb87cc7ce3b87548fa7617fd8f9e20636d2bcea5b08e9f5d1dc7d85a5",
                "md5": "4a2d015d9dd658773ace39203e6f2a24",
                "sha256": "8d0ed4951dad9e50383f4332821b9b58f6f5a5b8fb7338f86549c5ec02c15fb9"
            },
            "downloads": -1,
            "filename": "cachepot-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4a2d015d9dd658773ace39203e6f2a24",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 13501,
            "upload_time": "2024-10-15T16:30:33",
            "upload_time_iso_8601": "2024-10-15T16:30:33.051937Z",
            "url": "https://files.pythonhosted.org/packages/2a/89/0e7fb87cc7ce3b87548fa7617fd8f9e20636d2bcea5b08e9f5d1dc7d85a5/cachepot-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa88db63d9780847639cd52c067ace4823d36466b508b93bb5447b5b47e2cf7a",
                "md5": "afde69ed619e6a4ab9278b8fcbcb9dfa",
                "sha256": "690f1f028dd28b1d9fff3dc2c2c7774e1ba2875992014bd9fe41a8613580a124"
            },
            "downloads": -1,
            "filename": "cachepot-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "afde69ed619e6a4ab9278b8fcbcb9dfa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 33133,
            "upload_time": "2024-10-15T16:30:34",
            "upload_time_iso_8601": "2024-10-15T16:30:34.424602Z",
            "url": "https://files.pythonhosted.org/packages/fa/88/db63d9780847639cd52c067ace4823d36466b508b93bb5447b5b47e2cf7a/cachepot-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-15 16:30:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kitsuyui",
    "github_project": "cachepot",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cachepot"
}
        
Elapsed time: 1.38638s