wrapper.py 690 B

1234567891011121314151617181920212223242526272829
  1. from .adapter import CacheControlAdapter
  2. from .cache import DictCache
  3. def CacheControl(
  4. sess,
  5. cache=None,
  6. cache_etags=True,
  7. serializer=None,
  8. heuristic=None,
  9. controller_class=None,
  10. adapter_class=None,
  11. cacheable_methods=None,
  12. ):
  13. cache = DictCache() if cache is None else cache
  14. adapter_class = adapter_class or CacheControlAdapter
  15. adapter = adapter_class(
  16. cache,
  17. cache_etags=cache_etags,
  18. serializer=serializer,
  19. heuristic=heuristic,
  20. controller_class=controller_class,
  21. cacheable_methods=cacheable_methods,
  22. )
  23. sess.mount("http://", adapter)
  24. sess.mount("https://", adapter)
  25. return sess