{ "info": { "author": "hongweipeng", "author_email": "", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "Django Fragment Cache\n===============\n\nDjango provides template fragment caching, such as :\n```\n{% load cache %}\n{% cache 500 sidebar %}\n .. sidebar ..\n{% endcache %}\n```\nBut the variable `sidebar` still to be passed to the template every time, otherwise the fragment is blank when the cache expires.\n\nIf the data acquisition process is time consuming, then the fragment cache is to exist in name only.\n\nSo, this module provides another way to use the template cache.\n\n## How to use?\n\n### Install\n```\npip install django-fragment-cache\n```\nInstall Requires:\n- django >= 2\n\nedit your settings.py to add `fragment_cache` to your `NSTALLED_APPS`.\n```\nINSTALLED_APPS = (\n ...\n 'fragment_cache',\n ...\n)\n```\n\n### Use\nyou need provide a callable object to tell module how to get data, and the function return a dict.\n\n**only call function when cache expires.**\n\n```\nimport time\ndef get_data(num=10):\n time.sleep(3)\n return {'nums': list(range(num))}\n\ndef test(request):\n return render(request, 'test.html', {'get_data': get_data})\n```\n\nThe `{% fragment_cache %}` template tag is similar to `{% cache %}` , for example:\n```\n{% load fragment_cache %}\n{% fragment_cache 500 get_data %}\n