CacheDisk


NameCacheDisk JSON
Version 0.1 PyPI version JSON
download
home_pagehttps://github.com/emilamaj/CacheDisk
SummaryA lightweight in-memory caching library with disk persistence. Supports both sync and async functions.
upload_time2024-03-12 11:16:33
maintainer
docs_urlNone
authorEmile Amajar
requires_python>=3.6
licenseMIT
keywords cache caching disk cache-disk database key-value
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # CacheDisk

CacheDisk is a lightweight, in-memory caching library designed for Python, offering seamless disk persistence.
It provides a drop-in optimization for your frequently used sync/async functions, allowing you to cache their results and retrieve them from memory on subsequent calls.

## Features

- Easy-to-use decorators to cache the results of functions, both synchronously and asynchronously.
- Disk persistence allows your cache to survive across application restarts, enhancing data retrieval times for repeated operations.
- Flexible storage options with support for JSON and Pickle, choose according to your compatibility or performance needs.
- Culling functionality to remove infrequently used cache entries, ensuring that your cache does not grow unbounded.
- Configurable caching parameters allowing fine-tuned performance to match the needs of your application, by avoiding slow-downs caused by disk writes.

## Installation

CacheDisk is available on PyPi and can be installed using pip:

```bash
pip install cachedisk
```

## Quick Start

### Basic Caching Example

Here's a quick example to get you started with CacheDisk:

```python
from cachedisk import CacheDisk, CacheDiskConfig

# Optional: Configure CacheDisk to use JSON for serialization
CacheDiskConfig.use_json = True

@CacheDisk.sync_disk_cache()
def expensive_function(param1):
    # Simulate an expensive or time-consuming operation
    return some_expensive_computation(param1)

# First call will compute and cache the result
result = expensive_function('some_input')

# Subsequent calls with the same input will fetch the result from the cache
cached_result = expensive_function('some_input')
```

For asynchronous functions, simply use the `@CacheDisk.async_disk_cache()` decorator in a similar fashion.

### Configuring the Cache Directory

By default, CacheDisk uses a directory named `cache_data` in your current working directory. You can customize the cache directory as follows:

```python
CacheDiskConfig.cache_dir = '/path/to/your/custom/cache/directory'
```

### Committing Cache Changes

To manually trigger saving all pending cache changes to disk:

```python
CacheDisk.commit()
```

This can be particularly useful before application shutdown or after a batch of operations.

## Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue if you have feedback, ideas, or code improvements.

## License

CacheDisk is licensed under the MIT License. See [LICENSE](LICENSE) file for more details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/emilamaj/CacheDisk",
    "name": "CacheDisk",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "cache caching disk cache-disk database key-value",
    "author": "Emile Amajar",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/5b/cd/8fbe281a0e0f664c99e511a8981fade234b611e41dd4a6add381ee49d28e/CacheDisk-0.1.tar.gz",
    "platform": null,
    "description": "# CacheDisk\r\n\r\nCacheDisk is a lightweight, in-memory caching library designed for Python, offering seamless disk persistence.\r\nIt provides a drop-in optimization for your frequently used sync/async functions, allowing you to cache their results and retrieve them from memory on subsequent calls.\r\n\r\n## Features\r\n\r\n- Easy-to-use decorators to cache the results of functions, both synchronously and asynchronously.\r\n- Disk persistence allows your cache to survive across application restarts, enhancing data retrieval times for repeated operations.\r\n- Flexible storage options with support for JSON and Pickle, choose according to your compatibility or performance needs.\r\n- Culling functionality to remove infrequently used cache entries, ensuring that your cache does not grow unbounded.\r\n- Configurable caching parameters allowing fine-tuned performance to match the needs of your application, by avoiding slow-downs caused by disk writes.\r\n\r\n## Installation\r\n\r\nCacheDisk is available on PyPi and can be installed using pip:\r\n\r\n```bash\r\npip install cachedisk\r\n```\r\n\r\n## Quick Start\r\n\r\n### Basic Caching Example\r\n\r\nHere's a quick example to get you started with CacheDisk:\r\n\r\n```python\r\nfrom cachedisk import CacheDisk, CacheDiskConfig\r\n\r\n# Optional: Configure CacheDisk to use JSON for serialization\r\nCacheDiskConfig.use_json = True\r\n\r\n@CacheDisk.sync_disk_cache()\r\ndef expensive_function(param1):\r\n    # Simulate an expensive or time-consuming operation\r\n    return some_expensive_computation(param1)\r\n\r\n# First call will compute and cache the result\r\nresult = expensive_function('some_input')\r\n\r\n# Subsequent calls with the same input will fetch the result from the cache\r\ncached_result = expensive_function('some_input')\r\n```\r\n\r\nFor asynchronous functions, simply use the `@CacheDisk.async_disk_cache()` decorator in a similar fashion.\r\n\r\n### Configuring the Cache Directory\r\n\r\nBy default, CacheDisk uses a directory named `cache_data` in your current working directory. You can customize the cache directory as follows:\r\n\r\n```python\r\nCacheDiskConfig.cache_dir = '/path/to/your/custom/cache/directory'\r\n```\r\n\r\n### Committing Cache Changes\r\n\r\nTo manually trigger saving all pending cache changes to disk:\r\n\r\n```python\r\nCacheDisk.commit()\r\n```\r\n\r\nThis can be particularly useful before application shutdown or after a batch of operations.\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to submit a pull request or open an issue if you have feedback, ideas, or code improvements.\r\n\r\n## License\r\n\r\nCacheDisk is licensed under the MIT License. See [LICENSE](LICENSE) file for more details.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A lightweight in-memory caching library with disk persistence. Supports both sync and async functions.",
    "version": "0.1",
    "project_urls": {
        "Homepage": "https://github.com/emilamaj/CacheDisk"
    },
    "split_keywords": [
        "cache",
        "caching",
        "disk",
        "cache-disk",
        "database",
        "key-value"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0f3f6ad625ec34e414a47a5f41ec2e9fd2bfe7abf7bf32ab9c7369f0a7fc0242",
                "md5": "4dab888187861bb66ad4861e4f71d87d",
                "sha256": "a201cb948eea9a81a2bce42cd31f27772537f93da1521be7eb7438bdc85a8730"
            },
            "downloads": -1,
            "filename": "CacheDisk-0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4dab888187861bb66ad4861e4f71d87d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 5426,
            "upload_time": "2024-03-12T11:16:31",
            "upload_time_iso_8601": "2024-03-12T11:16:31.859004Z",
            "url": "https://files.pythonhosted.org/packages/0f/3f/6ad625ec34e414a47a5f41ec2e9fd2bfe7abf7bf32ab9c7369f0a7fc0242/CacheDisk-0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5bcd8fbe281a0e0f664c99e511a8981fade234b611e41dd4a6add381ee49d28e",
                "md5": "afc215c167b5be8ea1387fb48ca7b345",
                "sha256": "d26507921f6db2fc6aca23b64f6dc099c2d594375124a0bb3b657aa15aa69a14"
            },
            "downloads": -1,
            "filename": "CacheDisk-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "afc215c167b5be8ea1387fb48ca7b345",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 6302,
            "upload_time": "2024-03-12T11:16:33",
            "upload_time_iso_8601": "2024-03-12T11:16:33.143323Z",
            "url": "https://files.pythonhosted.org/packages/5b/cd/8fbe281a0e0f664c99e511a8981fade234b611e41dd4a6add381ee49d28e/CacheDisk-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-12 11:16:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "emilamaj",
    "github_project": "CacheDisk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "cachedisk"
}
        
Elapsed time: 0.20412s