This commit is contained in:
Anubhav Patel 2026-07-11 16:47:36 -07:00 committed by GitHub
commit fd3add9c83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 35 additions and 1 deletions

View File

@ -415,7 +415,7 @@ HttpCacheMiddleware
* :ref:`httpcache-policy-dummy`
You can change the HTTP cache policy with the :setting:`HTTPCACHE_POLICY`
setting. Or you can also implement your own policy.
setting. Or you can also :ref:`implement your own policy <httpcache-policy-custom>`.
.. reqmeta:: dont_cache
@ -487,6 +487,40 @@ RFC2616 policy
* ... probably others ..
.. _httpcache-policy-custom:
Writing your own policy
~~~~~~~~~~~~~~~~~~~~~~~
You can implement a cache policy by creating a class that
defines the methods described below.
.. module:: scrapy.extensions.httpcache
.. class:: CachePolicy
.. method:: should_cache_request(request)
Return True if the :class:`~scrapy.http.Request` is cacheable otherwise False
.. method:: should_cache_response(response, request)
Return True if :class:`~scrapy.http.Response` should be cached otherwise False
.. method:: is_cached_response_fresh(cachedresponse, request)
Return True if cached :class:`~scrapy.http.Response` has expired otherwise False
.. method:: is_cached_response_valid(cachedresponse, response, request)
Return True if cached :class:`~scrapy.http.Response` is valid otherwise False
In order to use this policy, set:
* :setting:`HTTPCACHE_POLICY` to the Python import path of your custom policy class.
.. _httpcache-storage-fs:
Filesystem storage backend (default)