skip-django-context-cache


Nameskip-django-context-cache JSON
Version 0.0.2.1 PyPI version JSON
download
home_pagehttps://github.com/skip-pay/django-context-cache
SummaryDjango context cache library.
upload_time2023-01-16 10:18:56
maintainer
docs_urlNone
authorLubos Matl
requires_python
licenseMIT
keywords django cache request cache
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Prolog
======

`Django-context-cache` extends the Django framework with a context cache that caches data per request or per decorated block.

Installation
------------

- Install `django-context-cache` with the `pip` command:

```bash
pip install django-context-cache
```

- Add `'context_cache.middleware.ContextCacheMiddleware'` to your `MIDDLEWARE`:

```python
MIDDLEWARE = [
    'context_cache.middleware.ContextCacheMiddleware',
    ...
]
```

Usage
-----
Imagine having an function or method which result you want to cache per request:

    import random
    import string
    from context_cache.decorators import cache_for_context
    
    @cache_for_context
    def get_random_string():
        letters = string.ascii_lowercase
        return ''.join(random.choice(letters) for i in range(10))


If you call function get_random_string more times the value will be get from cache:

    def view(request):
        get_random_string() == get_random_string() # should return True

If you want to cache an function out of requests, for example in the django command you can use the decorator `init_context_cache`. The decorator can be used as a context processor too:

    from django.core.management.base import BaseCommand, CommandError
    from context_cache.decorators import init_context_cache
    
    class Command(BaseCommand):
        
        @init_context_cache
        def handle(self, *args, **options):
            get_random_string() == get_random_string() # should return True

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/skip-pay/django-context-cache",
    "name": "skip-django-context-cache",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "django,cache,request cache",
    "author": "Lubos Matl",
    "author_email": "matllubos@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/97/06/8e1e88fda41a2f26076fc9484360d76984a3a07f7235b9be8ab62ae15f7b/skip-django-context-cache-0.0.2.1.tar.gz",
    "platform": null,
    "description": "Prolog\n======\n\n`Django-context-cache` extends the Django framework with a context cache that caches data per request or per decorated block.\n\nInstallation\n------------\n\n- Install `django-context-cache` with the `pip` command:\n\n```bash\npip install django-context-cache\n```\n\n- Add `'context_cache.middleware.ContextCacheMiddleware'` to your `MIDDLEWARE`:\n\n```python\nMIDDLEWARE = [\n    'context_cache.middleware.ContextCacheMiddleware',\n    ...\n]\n```\n\nUsage\n-----\nImagine having an function or method which result you want to cache per request:\n\n    import random\n    import string\n    from context_cache.decorators import cache_for_context\n    \n    @cache_for_context\n    def get_random_string():\n        letters = string.ascii_lowercase\n        return ''.join(random.choice(letters) for i in range(10))\n\n\nIf you call function get_random_string more times the value will be get from cache:\n\n    def view(request):\n        get_random_string() == get_random_string() # should return True\n\nIf you want to cache an function out of requests, for example in the django command you can use the decorator `init_context_cache`. The decorator can be used as a context processor too:\n\n    from django.core.management.base import BaseCommand, CommandError\n    from context_cache.decorators import init_context_cache\n    \n    class Command(BaseCommand):\n        \n        @init_context_cache\n        def handle(self, *args, **options):\n            get_random_string() == get_random_string() # should return True\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Django context cache library.",
    "version": "0.0.2.1",
    "split_keywords": [
        "django",
        "cache",
        "request cache"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "42dec568162b9d4ce8526af1920d27f017492cde91307cbeb05d755e777ec3d3",
                "md5": "5b3365d199a6aa09ca3ee493eb54a5b4",
                "sha256": "9a0cac4a748eca83ec8093fd9be6c15c1abd9fa5ccb8adeb73d89158b89bcba1"
            },
            "downloads": -1,
            "filename": "skip_django_context_cache-0.0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5b3365d199a6aa09ca3ee493eb54a5b4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10602,
            "upload_time": "2023-01-16T10:18:54",
            "upload_time_iso_8601": "2023-01-16T10:18:54.509857Z",
            "url": "https://files.pythonhosted.org/packages/42/de/c568162b9d4ce8526af1920d27f017492cde91307cbeb05d755e777ec3d3/skip_django_context_cache-0.0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "97068e1e88fda41a2f26076fc9484360d76984a3a07f7235b9be8ab62ae15f7b",
                "md5": "b5bb988ab034761347cb1f98e29e16a0",
                "sha256": "7033051e6bbed5a41d63064b8c1af7ec3ce0e88677cec9de8a4b29a698922041"
            },
            "downloads": -1,
            "filename": "skip-django-context-cache-0.0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b5bb988ab034761347cb1f98e29e16a0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8747,
            "upload_time": "2023-01-16T10:18:56",
            "upload_time_iso_8601": "2023-01-16T10:18:56.758082Z",
            "url": "https://files.pythonhosted.org/packages/97/06/8e1e88fda41a2f26076fc9484360d76984a3a07f7235b9be8ab62ae15f7b/skip-django-context-cache-0.0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-16 10:18:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "skip-pay",
    "github_project": "django-context-cache",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "skip-django-context-cache"
}
        
Elapsed time: 0.07669s