django-update-cache


Namedjango-update-cache JSON
Version 1.0.6 PyPI version JSON
download
home_pagehttps://github.com/bboogaard/django-update-cache
SummaryLazy cache updates for Django
upload_time2023-12-23 19:56:29
maintainer
docs_urlNone
authorBram Boogaard
requires_python
licenseMIT License
keywords django update cache
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-update-cache

Lazy cache updates for Django.

## Rationale

Cache function results with optional asynchronous updates.

## Support

Supports: Python 3.10.

Supports Django Versions: 4.2.7

## Installation

```shell
$ pip install django-update-cache
```

## Usage

Add `update_cache.apps.UpdateCacheConfig` to `INSTALLED_APPS`.

Run migrations:

```shell
python manage.py migrate
```

Add a module `cached_functions` to one or more of your apps. Decorate any function for which you want the results to be 
cached:

```python
# cached_functions.py
from update_cache.decorators import cache_function


@cache_function()
def my_expensive_function():
    ...
```

Specify a specific timeout:

```python
# cached_functions.py
from update_cache.decorators import cache_function


@cache_function(timeout=60)
def my_expensive_function():
    ...
```

Use asynchronous updating (this requires running a django_rq worker):

```python
# cached_functions.py
from update_cache.brokers import async_broker
from update_cache.decorators import cache_function


@cache_function(broker=async_broker)
def my_expensive_function():
    ...
```

Use a custom cache backend:

```python
# cached_functions.py
from update_cache.decorators import cache_function


@cache_function(backend='my_cache_alias')
def my_expensive_function():
    ...
```

You can set a global broker to delegate the cache updates in `settings.py`.

```python
DUC_DEFAULT_BROKER = 'update_cache.brokers.AsyncBroker'
```

Invalidate the cache:

```python
# cached_functions.py
from update_cache.decorators import cache_function


@cache_function()
def my_expensive_function():
    ...


my_expensive_function.cache.invalidate()
```

Cache a view (only synchronous updates).

```python
# cached_functions.py
from update_cache.decorators import cache_view


@cache_view()
def my_expensive_view():
    ...
```

View all cached entries in Django Admin:

![cached entries](./cache-entries.png "Cached entries")

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/bboogaard/django-update-cache",
    "name": "django-update-cache",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Django Update cache",
    "author": "Bram Boogaard",
    "author_email": "padawan@hetnet.nl",
    "download_url": "https://files.pythonhosted.org/packages/d5/31/76c09005a2c451bf142afbddd231d9c597eafed44669d3a112d95387da07/django-update-cache-1.0.6.tar.gz",
    "platform": null,
    "description": "# django-update-cache\n\nLazy cache updates for Django.\n\n## Rationale\n\nCache function results with optional asynchronous updates.\n\n## Support\n\nSupports: Python 3.10.\n\nSupports Django Versions: 4.2.7\n\n## Installation\n\n```shell\n$ pip install django-update-cache\n```\n\n## Usage\n\nAdd `update_cache.apps.UpdateCacheConfig` to `INSTALLED_APPS`.\n\nRun migrations:\n\n```shell\npython manage.py migrate\n```\n\nAdd a module `cached_functions` to one or more of your apps. Decorate any function for which you want the results to be \ncached:\n\n```python\n# cached_functions.py\nfrom update_cache.decorators import cache_function\n\n\n@cache_function()\ndef my_expensive_function():\n    ...\n```\n\nSpecify a specific timeout:\n\n```python\n# cached_functions.py\nfrom update_cache.decorators import cache_function\n\n\n@cache_function(timeout=60)\ndef my_expensive_function():\n    ...\n```\n\nUse asynchronous updating (this requires running a django_rq worker):\n\n```python\n# cached_functions.py\nfrom update_cache.brokers import async_broker\nfrom update_cache.decorators import cache_function\n\n\n@cache_function(broker=async_broker)\ndef my_expensive_function():\n    ...\n```\n\nUse a custom cache backend:\n\n```python\n# cached_functions.py\nfrom update_cache.decorators import cache_function\n\n\n@cache_function(backend='my_cache_alias')\ndef my_expensive_function():\n    ...\n```\n\nYou can set a global broker to delegate the cache updates in `settings.py`.\n\n```python\nDUC_DEFAULT_BROKER = 'update_cache.brokers.AsyncBroker'\n```\n\nInvalidate the cache:\n\n```python\n# cached_functions.py\nfrom update_cache.decorators import cache_function\n\n\n@cache_function()\ndef my_expensive_function():\n    ...\n\n\nmy_expensive_function.cache.invalidate()\n```\n\nCache a view (only synchronous updates).\n\n```python\n# cached_functions.py\nfrom update_cache.decorators import cache_view\n\n\n@cache_view()\ndef my_expensive_view():\n    ...\n```\n\nView all cached entries in Django Admin:\n\n![cached entries](./cache-entries.png \"Cached entries\")\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Lazy cache updates for Django",
    "version": "1.0.6",
    "project_urls": {
        "Homepage": "https://github.com/bboogaard/django-update-cache"
    },
    "split_keywords": [
        "django",
        "update",
        "cache"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2c4cec7456a18b71a125b9fc0551fce0484cebc09a5a4874ab71ea05c1174988",
                "md5": "d78220531c5f14beb6ab20554be7a561",
                "sha256": "a86f761f41272242ad579cabd20e9aab285debf22d18d95aead7bf6237af90cf"
            },
            "downloads": -1,
            "filename": "django_update_cache-1.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d78220531c5f14beb6ab20554be7a561",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11117,
            "upload_time": "2023-12-23T19:56:27",
            "upload_time_iso_8601": "2023-12-23T19:56:27.771278Z",
            "url": "https://files.pythonhosted.org/packages/2c/4c/ec7456a18b71a125b9fc0551fce0484cebc09a5a4874ab71ea05c1174988/django_update_cache-1.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d53176c09005a2c451bf142afbddd231d9c597eafed44669d3a112d95387da07",
                "md5": "8644b346c0ba4ab425131c878069603e",
                "sha256": "efba2e8fe25ec143ce034180602205eec4619045a3f39146d6dcc54ca8ef668f"
            },
            "downloads": -1,
            "filename": "django-update-cache-1.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "8644b346c0ba4ab425131c878069603e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 116312,
            "upload_time": "2023-12-23T19:56:29",
            "upload_time_iso_8601": "2023-12-23T19:56:29.213522Z",
            "url": "https://files.pythonhosted.org/packages/d5/31/76c09005a2c451bf142afbddd231d9c597eafed44669d3a112d95387da07/django-update-cache-1.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-23 19:56:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bboogaard",
    "github_project": "django-update-cache",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "django-update-cache"
}
        
Elapsed time: 0.15294s