cacherator


Namecacherator JSON
Version 1.0.5 PyPI version JSON
download
home_pageNone
SummaryA Python library for persistent JSON-based caching of class state and function results.
upload_time2024-11-24 07:46:43
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseMIT
keywords cache json data storage
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Cacherator

Cacherator is a Python package that provides persistent caching functionality for your Python classes and functions. It allows you to easily cache function results to disk, improving performance for expensive computations or API calls.

## Features

- Persistent caching of function results
- Customizable Time-To-Live (TTL) for cached data
- Option to clear cache on demand
- JSON-based storage for easy inspection and portability
- Automatic serialization and deserialization of cached data
- Support for instance methods and properties

## Installation

You can install PyCacherator using pip:

```bash
pip install cacherator
```

## Usage

### Basic Usage

To use Cacherator, simply inherit from the `JSONCache` class and use the `@Cached` decorator on your methods:

```python
from cacherator import JSONCache, Cached

class MyClass(JSONCache):
    def __init__(self, data_id):
        super().__init__(data_id=data_id)

    @Cached()
    def expensive_operation(self, arg1, arg2):
        # Your expensive computation here
        return result
```

### Customizing Cache Behavior

You can customize the caching behavior by passing arguments to the `JSONCache` constructor and the `@Cached` decorator:

```python
from datetime import timedelta
from cacherator import JSONCache, Cached

class MyClass(JSONCache):
    def __init__(self, data_id):
        super().__init__(
            data_id=data_id,
            directory="custom/cache/dir",
            clear_cache=False,
            ttl=timedelta(days=999),
            logging=True
        )

    @Cached(ttl=300, clear_cache=False)
    def cached_method(self, arg):
        # Method implementation
        return result
```

## API Reference

### JSONCache

The base class for objects with caching capabilities.

#### Parameters:

- `data_id` (str): Unique identifier for the cache instance.
- `directory` (str): Directory to store cache files (default: "json/data").
- `clear_cache` (bool): Whether to clear existing cache on instantiation (default: False).
- `ttl` (timedelta | int | float): Default Time-To-Live for cached data (default: 999 days).
- `logging` (bool): Enable logging of cache operations (default: True).

### @Cached

Decorator for caching method results.

#### Parameters:

- `ttl` (float | int | timedelta): Time-To-Live for the cached result (defaults to the ttl set on object level).
- `clear_cache` (bool): Whether to clear existing cache before execution (default: False).

## License

This project is licensed under the MIT License.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cacherator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "cache, json, data storage",
    "author": null,
    "author_email": "Arved Kl\u00f6hn <arved.kloehn@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/52/10/3b8dfa7c4cf5e6b58f2174013c3341857dda53ec7f26a64a5cd8eec971d5/cacherator-1.0.5.tar.gz",
    "platform": null,
    "description": "# Cacherator\r\n\r\nCacherator is a Python package that provides persistent caching functionality for your Python classes and functions. It allows you to easily cache function results to disk, improving performance for expensive computations or API calls.\r\n\r\n## Features\r\n\r\n- Persistent caching of function results\r\n- Customizable Time-To-Live (TTL) for cached data\r\n- Option to clear cache on demand\r\n- JSON-based storage for easy inspection and portability\r\n- Automatic serialization and deserialization of cached data\r\n- Support for instance methods and properties\r\n\r\n## Installation\r\n\r\nYou can install PyCacherator using pip:\r\n\r\n```bash\r\npip install cacherator\r\n```\r\n\r\n## Usage\r\n\r\n### Basic Usage\r\n\r\nTo use Cacherator, simply inherit from the `JSONCache` class and use the `@Cached` decorator on your methods:\r\n\r\n```python\r\nfrom cacherator import JSONCache, Cached\r\n\r\nclass MyClass(JSONCache):\r\n    def __init__(self, data_id):\r\n        super().__init__(data_id=data_id)\r\n\r\n    @Cached()\r\n    def expensive_operation(self, arg1, arg2):\r\n        # Your expensive computation here\r\n        return result\r\n```\r\n\r\n### Customizing Cache Behavior\r\n\r\nYou can customize the caching behavior by passing arguments to the `JSONCache` constructor and the `@Cached` decorator:\r\n\r\n```python\r\nfrom datetime import timedelta\r\nfrom cacherator import JSONCache, Cached\r\n\r\nclass MyClass(JSONCache):\r\n    def __init__(self, data_id):\r\n        super().__init__(\r\n            data_id=data_id,\r\n            directory=\"custom/cache/dir\",\r\n            clear_cache=False,\r\n            ttl=timedelta(days=999),\r\n            logging=True\r\n        )\r\n\r\n    @Cached(ttl=300, clear_cache=False)\r\n    def cached_method(self, arg):\r\n        # Method implementation\r\n        return result\r\n```\r\n\r\n## API Reference\r\n\r\n### JSONCache\r\n\r\nThe base class for objects with caching capabilities.\r\n\r\n#### Parameters:\r\n\r\n- `data_id` (str): Unique identifier for the cache instance.\r\n- `directory` (str): Directory to store cache files (default: \"json/data\").\r\n- `clear_cache` (bool): Whether to clear existing cache on instantiation (default: False).\r\n- `ttl` (timedelta | int | float): Default Time-To-Live for cached data (default: 999 days).\r\n- `logging` (bool): Enable logging of cache operations (default: True).\r\n\r\n### @Cached\r\n\r\nDecorator for caching method results.\r\n\r\n#### Parameters:\r\n\r\n- `ttl` (float | int | timedelta): Time-To-Live for the cached result (defaults to the ttl set on object level).\r\n- `clear_cache` (bool): Whether to clear existing cache before execution (default: False).\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python library for persistent JSON-based caching of class state and function results.",
    "version": "1.0.5",
    "project_urls": {
        "Source": "https://github.com/Redundando/cacherator"
    },
    "split_keywords": [
        "cache",
        " json",
        " data storage"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a6b7eb6a01d9e06c5616e89afe7fb1d32a3a8a5fb4639ed109c630e0e7264fb8",
                "md5": "245397e893ed874c7e1df32a3b40124f",
                "sha256": "eddf1c87bf6eeee8352806cdaa7c89aa9b54ebcbd0f8fa925bb105ae53330150"
            },
            "downloads": -1,
            "filename": "cacherator-1.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "245397e893ed874c7e1df32a3b40124f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 9482,
            "upload_time": "2024-11-24T07:46:41",
            "upload_time_iso_8601": "2024-11-24T07:46:41.874051Z",
            "url": "https://files.pythonhosted.org/packages/a6/b7/eb6a01d9e06c5616e89afe7fb1d32a3a8a5fb4639ed109c630e0e7264fb8/cacherator-1.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "52103b8dfa7c4cf5e6b58f2174013c3341857dda53ec7f26a64a5cd8eec971d5",
                "md5": "62c708d1ed38e71af89387ec371e0aa7",
                "sha256": "5548b1568fb7c02d056ff0c4085e74399f87ab2dd543791b62e80192618baa4f"
            },
            "downloads": -1,
            "filename": "cacherator-1.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "62c708d1ed38e71af89387ec371e0aa7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9407,
            "upload_time": "2024-11-24T07:46:43",
            "upload_time_iso_8601": "2024-11-24T07:46:43.497377Z",
            "url": "https://files.pythonhosted.org/packages/52/10/3b8dfa7c4cf5e6b58f2174013c3341857dda53ec7f26a64a5cd8eec971d5/cacherator-1.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-24 07:46:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Redundando",
    "github_project": "cacherator",
    "github_not_found": true,
    "lcname": "cacherator"
}
        
Elapsed time: 2.48339s