cachetoolz


Namecachetoolz JSON
Version 0.3.3 PyPI version JSON
download
home_pageNone
SummaryThis library provides a decorator for caching functions
upload_time2024-02-29 23:18:03
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords async cache mongo python redis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Cache Toolz

[![License MIT](https://img.shields.io/pypi/l/cachetoolz?label=License&color=%234B78E6)](https://codeberg.org/taconi/cachetoolz/src/branch/main/LICENSE)
[![status-badge](https://ci.codeberg.org/api/badges/13098/status.svg)](https://ci.codeberg.org/repos/13098)
[![codecov](https://img.shields.io/codecov/c/github/taconi/cachetoolz?logo=codecov&style=flat&label=Coverage&color=%2373DC8C)](https://codecov.io/gh/taconi/cachetoolz)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/cachetoolz.svg?logo=python&label=Python&color=%234B78E6)](https://pypi.python.org/pypi/cachetoolz/)
[![PyPI version](https://img.shields.io/pypi/v/cachetoolz.svg?logo=pypi&label=PyPI&color=%23FA9BFA)](https://pypi.org/project/cachetoolz/)
[![Downloads](https://img.shields.io/pypi/dm/cachetoolz?logo=pypi&label=Downloads&color=%2373DC8C)](https://pypi.org/project/cachetoolz/)
[![Documentation](https://img.shields.io/badge/Documentation-1769AA?color=%234B78E6)](https://cachetoolz.readthedocs.io)
[![Changelog](https://img.shields.io/badge/Changelog-1769AA?color=%2373DC8C)](https://cachetoolz.readthedocs.io/changelog)
[![Issue Tracker](https://img.shields.io/badge/Issue%20Tracker-1769AA?color=%23FA9BFA)]("https://codeberg.org/taconi/cachetoolz/issues")
[![Contributing](https://img.shields.io/badge/Contributing-1769AA?color=%234B78E6)](https://cachetoolz.readthedocs.io/contributing)
[![Built with Material for MkDocs](https://img.shields.io/badge/Material_for_MkDocs-526CFE?logo=MaterialForMkDocs&logoColor=white)](https://squidfunk.github.io/mkdocs-material/)

This library offers a decorator that enhances the functionality of caching functions.

Caching is a technique commonly used in software development to improve performance by storing the results of expensive or time-consuming function calls. With this library, you can easily apply caching to your functions using a decorator.

The decorator provided by this library automatically checks if the function has been called with the same set of arguments before. If it has, instead of executing the function again, it returns the cached result, saving valuable processing time. However, if the function is called with new or different arguments, it will execute normally and cache the result for future use.

By incorporating this caching decorator into your code, you can optimize the execution of functions that involve complex computations, database queries, API calls, or any other operations that could benefit from caching.

Overall, this library simplifies the implementation of caching in your applications, allowing you to enhance performance and reduce resource consumption effectively.

# Installation

Install and update using [pip](https://pip.pypa.io/en/stable/getting-started/):

```{.sh linenums=0}
pip install cachetoolz
```

# A Example

```python title="todo.py" hl_lines="16-17 25-26 30-31 35-36"
from dataclasses import asdict, dataclass, field
from datetime import timedelta
from uuid import UUID, uuid4

from cachetoolz import cache
from cachetoolz.coder import coder

TODOS: list['Todo'] = []

@dataclass
class Todo:
    title: str
    status: bool = field(default=False, compare=False)
    id: UUID = field(default_factory=uuid4, compare=False)

# Registering an object coder
@coder.register
class TodoSerializer:
    def encode(self, value: Todo):  # Need type annotated
        return asdict(value)

    def decode(self, value):
        return Todo(**value)

# Adding cache to function with expiry time in seconds
@cache(ttl=120, namespace='todo')
def get_one(id: UUID):
    return next(filter(lambda todo: todo.id == id, TODOS), None)

# Adding expiry time using timedelta
@cache(ttl=timedelta(minutes=30), namespace='todo')
def get_all():
    return TODOS

# Clear all caches on given namesoaces
@cache.clear(namespaces=['todo'])
def add_one(title, status=False):
    if (todo := Todo(title=title, status=status)) not in TODOS:
        TODOS.append(todo)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cachetoolz",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Igor Taconi <igor.taconi@protonmail.com>",
    "keywords": "async,cache,mongo,python,redis",
    "author": null,
    "author_email": "Igor Taconi <igor.taconi@protonmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/c3/14/3f09464e4bf5491c0bd3e9bc57bd84f8a1232c31e2e19358e98b1a2c9a8b/cachetoolz-0.3.3.tar.gz",
    "platform": null,
    "description": "# Cache Toolz\n\n[![License MIT](https://img.shields.io/pypi/l/cachetoolz?label=License&color=%234B78E6)](https://codeberg.org/taconi/cachetoolz/src/branch/main/LICENSE)\n[![status-badge](https://ci.codeberg.org/api/badges/13098/status.svg)](https://ci.codeberg.org/repos/13098)\n[![codecov](https://img.shields.io/codecov/c/github/taconi/cachetoolz?logo=codecov&style=flat&label=Coverage&color=%2373DC8C)](https://codecov.io/gh/taconi/cachetoolz)\n[![Supported Python versions](https://img.shields.io/pypi/pyversions/cachetoolz.svg?logo=python&label=Python&color=%234B78E6)](https://pypi.python.org/pypi/cachetoolz/)\n[![PyPI version](https://img.shields.io/pypi/v/cachetoolz.svg?logo=pypi&label=PyPI&color=%23FA9BFA)](https://pypi.org/project/cachetoolz/)\n[![Downloads](https://img.shields.io/pypi/dm/cachetoolz?logo=pypi&label=Downloads&color=%2373DC8C)](https://pypi.org/project/cachetoolz/)\n[![Documentation](https://img.shields.io/badge/Documentation-1769AA?color=%234B78E6)](https://cachetoolz.readthedocs.io)\n[![Changelog](https://img.shields.io/badge/Changelog-1769AA?color=%2373DC8C)](https://cachetoolz.readthedocs.io/changelog)\n[![Issue Tracker](https://img.shields.io/badge/Issue%20Tracker-1769AA?color=%23FA9BFA)](\"https://codeberg.org/taconi/cachetoolz/issues\")\n[![Contributing](https://img.shields.io/badge/Contributing-1769AA?color=%234B78E6)](https://cachetoolz.readthedocs.io/contributing)\n[![Built with Material for MkDocs](https://img.shields.io/badge/Material_for_MkDocs-526CFE?logo=MaterialForMkDocs&logoColor=white)](https://squidfunk.github.io/mkdocs-material/)\n\nThis library offers a decorator that enhances the functionality of caching functions.\n\nCaching is a technique commonly used in software development to improve performance by storing the results of expensive or time-consuming function calls. With this library, you can easily apply caching to your functions using a decorator.\n\nThe decorator provided by this library automatically checks if the function has been called with the same set of arguments before. If it has, instead of executing the function again, it returns the cached result, saving valuable processing time. However, if the function is called with new or different arguments, it will execute normally and cache the result for future use.\n\nBy incorporating this caching decorator into your code, you can optimize the execution of functions that involve complex computations, database queries, API calls, or any other operations that could benefit from caching.\n\nOverall, this library simplifies the implementation of caching in your applications, allowing you to enhance performance and reduce resource consumption effectively.\n\n# Installation\n\nInstall and update using [pip](https://pip.pypa.io/en/stable/getting-started/):\n\n```{.sh linenums=0}\npip install cachetoolz\n```\n\n# A Example\n\n```python title=\"todo.py\" hl_lines=\"16-17 25-26 30-31 35-36\"\nfrom dataclasses import asdict, dataclass, field\nfrom datetime import timedelta\nfrom uuid import UUID, uuid4\n\nfrom cachetoolz import cache\nfrom cachetoolz.coder import coder\n\nTODOS: list['Todo'] = []\n\n@dataclass\nclass Todo:\n    title: str\n    status: bool = field(default=False, compare=False)\n    id: UUID = field(default_factory=uuid4, compare=False)\n\n# Registering an object coder\n@coder.register\nclass TodoSerializer:\n    def encode(self, value: Todo):  # Need type annotated\n        return asdict(value)\n\n    def decode(self, value):\n        return Todo(**value)\n\n# Adding cache to function with expiry time in seconds\n@cache(ttl=120, namespace='todo')\ndef get_one(id: UUID):\n    return next(filter(lambda todo: todo.id == id, TODOS), None)\n\n# Adding expiry time using timedelta\n@cache(ttl=timedelta(minutes=30), namespace='todo')\ndef get_all():\n    return TODOS\n\n# Clear all caches on given namesoaces\n@cache.clear(namespaces=['todo'])\ndef add_one(title, status=False):\n    if (todo := Todo(title=title, status=status)) not in TODOS:\n        TODOS.append(todo)\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "This library provides a decorator for caching functions",
    "version": "0.3.3",
    "project_urls": {
        "Changelog": "https://cachetoolz.readthedocs.io/changelog",
        "Contributing": "https://cachetoolz.readthedocs.io/contributing",
        "Documentation": "https://cachetoolz.readthedocs.io",
        "Homepage": "https://codeberg.org/taconi/cachetoolz/#cache-toolz",
        "Issue Tracker": "https://codeberg.org/taconi/cachetoolz/issues",
        "Repository": "https://codeberg.org/taconi/cachetoolz/"
    },
    "split_keywords": [
        "async",
        "cache",
        "mongo",
        "python",
        "redis"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7d7c4170dc51eace14cc2021b0f05fcb292cb9a70f88fc69576e816197c85643",
                "md5": "4e379a24808a5199b68d47d9b8ccebf4",
                "sha256": "8e810cd4292a8d0a122540f7c006d464d5814009583383ad3e41f9e9e9ee1424"
            },
            "downloads": -1,
            "filename": "cachetoolz-0.3.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4e379a24808a5199b68d47d9b8ccebf4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 17997,
            "upload_time": "2024-02-29T23:18:02",
            "upload_time_iso_8601": "2024-02-29T23:18:02.549940Z",
            "url": "https://files.pythonhosted.org/packages/7d/7c/4170dc51eace14cc2021b0f05fcb292cb9a70f88fc69576e816197c85643/cachetoolz-0.3.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c3143f09464e4bf5491c0bd3e9bc57bd84f8a1232c31e2e19358e98b1a2c9a8b",
                "md5": "837898ee76fd87bc7c5f8beeb1011992",
                "sha256": "62da299b7514c15c88eff80a1a96f0c1e923a09ae3baa611171892268b8679ec"
            },
            "downloads": -1,
            "filename": "cachetoolz-0.3.3.tar.gz",
            "has_sig": false,
            "md5_digest": "837898ee76fd87bc7c5f8beeb1011992",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 13820,
            "upload_time": "2024-02-29T23:18:03",
            "upload_time_iso_8601": "2024-02-29T23:18:03.949808Z",
            "url": "https://files.pythonhosted.org/packages/c3/14/3f09464e4bf5491c0bd3e9bc57bd84f8a1232c31e2e19358e98b1a2c9a8b/cachetoolz-0.3.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-29 23:18:03",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": true,
    "codeberg_user": "taconi",
    "codeberg_project": "cachetoolz",
    "lcname": "cachetoolz"
}
        
Elapsed time: 0.21686s