Python django.core.cache.InvalidCacheBackendError() Examples
The following are 14
code examples of django.core.cache.InvalidCacheBackendError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.core.cache
, or try the search function
.
Example #1
Source File: cull_mysql_caches.py From django-mysql with BSD 3-Clause "New" or "Revised" License | 6 votes |
def handle(self, *args, **options): verbosity = options.get("verbosity") aliases = set(options["aliases"]) if not aliases: aliases = settings.CACHES for alias in aliases: try: cache = caches[alias] except InvalidCacheBackendError: raise CommandError("Cache '{}' does not exist".format(alias)) if not isinstance(cache, MySQLCache): # pragma: no cover continue if verbosity >= 1: self.stdout.write( "Deleting from cache '{}'... ".format(alias), ending="" ) num_deleted = cache.cull() if verbosity >= 1: self.stdout.write("{} entries deleted.".format(num_deleted))
Example #2
Source File: mysql_cache_migration.py From django-mysql with BSD 3-Clause "New" or "Revised" License | 6 votes |
def handle(self, *args, **options): aliases = set(options["aliases"]) if not aliases: aliases = settings.CACHES tables = set() for alias in aliases: try: cache = caches[alias] except InvalidCacheBackendError: raise CommandError("Cache '{}' does not exist".format(alias)) if not isinstance(cache, MySQLCache): # pragma: no cover continue tables.add(cache._table) if not tables: self.stderr.write("No MySQLCache instances in CACHES") return migration = self.render_migration(tables) self.stdout.write(migration)
Example #3
Source File: cache.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def render(self, context): try: expire_time = self.expire_time_var.resolve(context) except VariableDoesNotExist: raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.expire_time_var.var) try: expire_time = int(expire_time) except (ValueError, TypeError): raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time) if self.cache_name: try: cache_name = self.cache_name.resolve(context) except VariableDoesNotExist: raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.cache_name.var) try: fragment_cache = caches[cache_name] except InvalidCacheBackendError: raise TemplateSyntaxError('Invalid cache name specified for cache tag: %r' % cache_name) else: try: fragment_cache = caches['template_fragments'] except InvalidCacheBackendError: fragment_cache = caches['default'] vary_on = [var.resolve(context) for var in self.vary_on] cache_key = make_template_fragment_key(self.fragment_name, vary_on) value = fragment_cache.get(cache_key) if value is None: value = self.nodelist.render(context) fragment_cache.set(cache_key, value, expire_time) return value
Example #4
Source File: cache.py From bioforum with MIT License | 5 votes |
def render(self, context): try: expire_time = self.expire_time_var.resolve(context) except VariableDoesNotExist: raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.expire_time_var.var) if expire_time is not None: try: expire_time = int(expire_time) except (ValueError, TypeError): raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time) if self.cache_name: try: cache_name = self.cache_name.resolve(context) except VariableDoesNotExist: raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.cache_name.var) try: fragment_cache = caches[cache_name] except InvalidCacheBackendError: raise TemplateSyntaxError('Invalid cache name specified for cache tag: %r' % cache_name) else: try: fragment_cache = caches['template_fragments'] except InvalidCacheBackendError: fragment_cache = caches['default'] vary_on = [var.resolve(context) for var in self.vary_on] cache_key = make_template_fragment_key(self.fragment_name, vary_on) value = fragment_cache.get(cache_key) if value is None: value = self.nodelist.render(context) fragment_cache.set(cache_key, value, expire_time) return value
Example #5
Source File: __init__.py From django-q with MIT License | 5 votes |
def get_cache(): """ Gets the current cache provider :return: a cache provider """ try: return caches[Conf.CACHE] except InvalidCacheBackendError: return None
Example #6
Source File: test_sessions.py From django-cassandra-engine with BSD 2-Clause "Simplified" License | 5 votes |
def test_non_default_cache(self): # 21000 - CacheDB backend should respect SESSION_CACHE_ALIAS. with self.assertRaises(InvalidCacheBackendError): self.backend()
Example #7
Source File: cache.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def render(self, context): try: expire_time = self.expire_time_var.resolve(context) except VariableDoesNotExist: raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.expire_time_var.var) if expire_time is not None: try: expire_time = int(expire_time) except (ValueError, TypeError): raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time) if self.cache_name: try: cache_name = self.cache_name.resolve(context) except VariableDoesNotExist: raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.cache_name.var) try: fragment_cache = caches[cache_name] except InvalidCacheBackendError: raise TemplateSyntaxError('Invalid cache name specified for cache tag: %r' % cache_name) else: try: fragment_cache = caches['template_fragments'] except InvalidCacheBackendError: fragment_cache = caches['default'] vary_on = [var.resolve(context) for var in self.vary_on] cache_key = make_template_fragment_key(self.fragment_name, vary_on) value = fragment_cache.get(cache_key) if value is None: value = self.nodelist.render(context) fragment_cache.set(cache_key, value, expire_time) return value
Example #8
Source File: throttles.py From course-discovery with GNU Affero General Public License v3.0 | 5 votes |
def throttling_cache(): """ Returns the cache specifically used for throttling. """ try: return caches['throttling'] except InvalidCacheBackendError: return caches['default']
Example #9
Source File: models.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def purge_from_cache(self): try: cache = caches['renditions'] cache.delete(self.construct_cache_key( self.image_id, self.focal_point_key, self.filter_spec )) except InvalidCacheBackendError: pass
Example #10
Source File: cache.py From python with Apache License 2.0 | 5 votes |
def render(self, context): try: expire_time = self.expire_time_var.resolve(context) except VariableDoesNotExist: raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.expire_time_var.var) try: expire_time = int(expire_time) except (ValueError, TypeError): raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time) if self.cache_name: try: cache_name = self.cache_name.resolve(context) except VariableDoesNotExist: raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.cache_name.var) try: fragment_cache = caches[cache_name] except InvalidCacheBackendError: raise TemplateSyntaxError('Invalid cache name specified for cache tag: %r' % cache_name) else: try: fragment_cache = caches['template_fragments'] except InvalidCacheBackendError: fragment_cache = caches['default'] vary_on = [var.resolve(context) for var in self.vary_on] cache_key = make_template_fragment_key(self.fragment_name, vary_on) value = fragment_cache.get(cache_key) if value is None: value = self.nodelist.render(context) fragment_cache.set(cache_key, value, expire_time) return value
Example #11
Source File: cache.py From openhgsenti with Apache License 2.0 | 5 votes |
def render(self, context): try: expire_time = self.expire_time_var.resolve(context) except VariableDoesNotExist: raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.expire_time_var.var) try: expire_time = int(expire_time) except (ValueError, TypeError): raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time) if self.cache_name: try: cache_name = self.cache_name.resolve(context) except VariableDoesNotExist: raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.cache_name.var) try: fragment_cache = caches[cache_name] except InvalidCacheBackendError: raise TemplateSyntaxError('Invalid cache name specified for cache tag: %r' % cache_name) else: try: fragment_cache = caches['template_fragments'] except InvalidCacheBackendError: fragment_cache = caches['default'] vary_on = [var.resolve(context) for var in self.vary_on] cache_key = make_template_fragment_key(self.fragment_name, vary_on) value = fragment_cache.get(cache_key) if value is None: value = self.nodelist.render(context) fragment_cache.set(cache_key, value, expire_time) return value
Example #12
Source File: cache.py From python2017 with MIT License | 5 votes |
def render(self, context): try: expire_time = self.expire_time_var.resolve(context) except VariableDoesNotExist: raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.expire_time_var.var) try: expire_time = int(expire_time) except (ValueError, TypeError): raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time) if self.cache_name: try: cache_name = self.cache_name.resolve(context) except VariableDoesNotExist: raise TemplateSyntaxError('"cache" tag got an unknown variable: %r' % self.cache_name.var) try: fragment_cache = caches[cache_name] except InvalidCacheBackendError: raise TemplateSyntaxError('Invalid cache name specified for cache tag: %r' % cache_name) else: try: fragment_cache = caches['template_fragments'] except InvalidCacheBackendError: fragment_cache = caches['default'] vary_on = [var.resolve(context) for var in self.vary_on] cache_key = make_template_fragment_key(self.fragment_name, vary_on) value = fragment_cache.get(cache_key) if value is None: value = self.nodelist.render(context) fragment_cache.set(cache_key, value, expire_time) return value
Example #13
Source File: memcached.py From django-elasticache with MIT License | 5 votes |
def __init__(self, server, params): self.update_params(params) super(ElastiCache, self).__init__(server, params) if len(self._servers) > 1: raise InvalidCacheBackendError( 'ElastiCache should be configured with only one server ' '(Configuration Endpoint)') if len(self._servers[0].split(':')) != 2: raise InvalidCacheBackendError( 'Server configuration should be in format IP:port') self._ignore_cluster_errors = self._options.get( 'IGNORE_CLUSTER_ERRORS', False)
Example #14
Source File: models.py From wagtail with BSD 3-Clause "New" or "Revised" License | 4 votes |
def get_rendition(self, filter): if isinstance(filter, str): filter = Filter(spec=filter) cache_key = filter.get_cache_key(self) Rendition = self.get_rendition_model() try: rendition_caching = True cache = caches['renditions'] rendition_cache_key = Rendition.construct_cache_key( self.id, cache_key, filter.spec ) cached_rendition = cache.get(rendition_cache_key) if cached_rendition: return cached_rendition except InvalidCacheBackendError: rendition_caching = False try: rendition = self.renditions.get( filter_spec=filter.spec, focal_point_key=cache_key, ) except Rendition.DoesNotExist: # Generate the rendition image generated_image = filter.run(self, BytesIO()) # Generate filename input_filename = os.path.basename(self.file.name) input_filename_without_extension, input_extension = os.path.splitext(input_filename) # A mapping of image formats to extensions FORMAT_EXTENSIONS = { 'jpeg': '.jpg', 'png': '.png', 'gif': '.gif', 'webp': '.webp', } output_extension = filter.spec.replace('|', '.') + FORMAT_EXTENSIONS[generated_image.format_name] if cache_key: output_extension = cache_key + '.' + output_extension # Truncate filename to prevent it going over 60 chars output_filename_without_extension = input_filename_without_extension[:(59 - len(output_extension))] output_filename = output_filename_without_extension + '.' + output_extension rendition, created = self.renditions.get_or_create( filter_spec=filter.spec, focal_point_key=cache_key, defaults={'file': File(generated_image.f, name=output_filename)} ) if rendition_caching: cache.set(rendition_cache_key, rendition) return rendition