base.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """
  2. flask_caching.backends.base
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. This module contains the BaseCache that other caching
  5. backends have to implement.
  6. :copyright: (c) 2018 by Peter Justin.
  7. :copyright: (c) 2010 by Thadeus Burgess.
  8. :license: BSD, see LICENSE for more details.
  9. """
  10. from cachelib import BaseCache as CachelibBaseCache
  11. class BaseCache(CachelibBaseCache):
  12. """Baseclass for the cache systems. All the cache systems implement this
  13. API or a superset of it.
  14. :param default_timeout: The default timeout (in seconds) that is used if
  15. no timeout is specified on :meth:`set`. A timeout
  16. of 0 indicates that the cache never expires.
  17. """
  18. def __init__(self, default_timeout=300):
  19. CachelibBaseCache.__init__(self, default_timeout=default_timeout)
  20. self.ignore_errors = False
  21. @classmethod
  22. def factory(cls, app, config, args, kwargs):
  23. return cls()
  24. def delete_many(self, *keys):
  25. """Deletes multiple keys at once.
  26. :param keys: The function accepts multiple keys as positional
  27. arguments.
  28. :returns: A list containing all sucessfuly deleted keys
  29. :rtype: boolean
  30. """
  31. deleted_keys = []
  32. for key in keys:
  33. if self.delete(key):
  34. deleted_keys.append(key)
  35. else:
  36. if not self.ignore_errors:
  37. break
  38. return deleted_keys