wrapper.py 774 B

123456789101112131415161718192021222324252627282930313233
  1. # SPDX-FileCopyrightText: 2015 Eric Larson
  2. #
  3. # SPDX-License-Identifier: Apache-2.0
  4. from .adapter import CacheControlAdapter
  5. from .cache import DictCache
  6. def CacheControl(
  7. sess,
  8. cache=None,
  9. cache_etags=True,
  10. serializer=None,
  11. heuristic=None,
  12. controller_class=None,
  13. adapter_class=None,
  14. cacheable_methods=None,
  15. ):
  16. cache = DictCache() if cache is None else cache
  17. adapter_class = adapter_class or CacheControlAdapter
  18. adapter = adapter_class(
  19. cache,
  20. cache_etags=cache_etags,
  21. serializer=serializer,
  22. heuristic=heuristic,
  23. controller_class=controller_class,
  24. cacheable_methods=cacheable_methods,
  25. )
  26. sess.mount("http://", adapter)
  27. sess.mount("https://", adapter)
  28. return sess