{"id":22196687,"url":"https://github.com/druids/django-context-cache","last_synced_at":"2025-08-01T17:35:16.524Z","repository":{"id":57419511,"uuid":"259580460","full_name":"druids/django-context-cache","owner":"druids","description":"django-context-cache","archived":false,"fork":false,"pushed_at":"2020-04-28T13:03:57.000Z","size":11,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-29T15:03:49.549Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/druids.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-28T08:43:30.000Z","updated_at":"2020-04-28T13:03:54.000Z","dependencies_parsed_at":"2022-09-03T09:41:00.657Z","dependency_job_id":null,"html_url":"https://github.com/druids/django-context-cache","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/druids/django-context-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/druids%2Fdjango-context-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/druids%2Fdjango-context-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/druids%2Fdjango-context-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/druids%2Fdjango-context-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/druids","download_url":"https://codeload.github.com/druids/django-context-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/druids%2Fdjango-context-cache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268267254,"owners_count":24222840,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-02T14:16:06.265Z","updated_at":"2025-08-01T17:35:16.481Z","avatar_url":"https://github.com/druids.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdruids%2Fdjango-context-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdruids%2Fdjango-context-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdruids%2Fdjango-context-cache/lists"}