def clear_actors_cache( film ): from film20.core.film_views import MAX_ACTORS cache.delete_cache( cache.CACHE_FILM_ACTORS, "%s_%s_%s" % ( film.permalink, 0, MAX_ACTORS ) ) cache.delete_cache( cache.CACHE_FILM_ACTORS, "%s_%s_%s" % ( film.permalink, MAX_ACTORS, 100 ) ) cache.delete( cache.Key( 'film_actors', film ) )
def invalidate(self): cache_prefix, cache_timeout = getattr(self, 'cache_params', (None, None)) cache_key = self._make_key() if cache_key: # give a chance to postprocess function to invalidate internal caches self.postprocess_query(iter(self), invalidate_cache=True) cache.delete(cache_key) return True logger.warning("invalidate without cache") return False
def update_nearby_cinemas(instance, distance=30): nearby = () UserChannel.objects.filter(user=instance.user, channel__type=TYPE_CINEMA).delete() if instance.latitude is not None and instance.longitude is not None and \ instance.country in settings.COUNTRIES_WITH_SHOWTIMES: nearby = list(Channel.objects.theaters().nearby(instance.latitude, instance.longitude, distance)) towns = set() if nearby: for i in nearby: towns.add(i.town_id) if len(towns)>2: break UserChannel(channel=i, user=instance.user, distance=str(i.distance)).save() cache.delete(cache.Key("user_channels", instance.user)) return nearby
def get_avatar_path(user, size, **kw): url = None is_username = isinstance(user, basestring) if settings.CACHE_AVATARS: key = cache.Key("avatar", str(user), str(size)) url = cache.get(key) # FLM-694 if url is not None and not os.path.exists( os.path.join( settings.MEDIA_ROOT, url ) ): logger.debug( "cached avatar %s does not exists ! [REMOVING]" % url ) url = None cache.delete(key) if not url: avatar_path = DEFAULT_AVATAR try: # if is_username is True, user variable is username as text, used by # useractivities if is_username: avatar = Avatar.objects.get(user__username=user, valid=True).image else: avatar = Avatar.objects.get(user=user, valid=True).image if avatar: path = os.path.join(settings.MEDIA_ROOT, unicode(avatar)) if os.path.isfile(path): avatar_path = path except Avatar.DoesNotExist: pass path, ext = os.path.splitext(avatar_path) thumb_path = "%s.%s%s" % (path, size, ext) valid = True if not os.path.isfile(thumb_path): try: image = Image.open(avatar_path) image.thumbnail((size, size), Image.ANTIALIAS) image.save(thumb_path, "JPEG") logger.debug("new avatar generated: %s", thumb_path) except IOError, e: logger.warning(e) valid = False url = thumb_path.replace(settings.MEDIA_ROOT, '') # eventually cache (if caching allowed) if settings.CACHE_AVATARS and valid and url: cache.set(key, url) logger.debug("Storing avatar in cache under %s" % key)
def update_nearby_cinemas(instance, distance=30): nearby = () UserChannel.objects.filter(user=instance.user, channel__type=TYPE_CINEMA).delete() if instance.latitude is not None and instance.longitude is not None and \ instance.country in settings.COUNTRIES_WITH_SHOWTIMES: nearby = list(Channel.objects.theaters().nearby( instance.latitude, instance.longitude, distance)) towns = set() if nearby: for i in nearby: towns.add(i.town_id) if len(towns) > 2: break UserChannel(channel=i, user=instance.user, distance=str(i.distance)).save() cache.delete(cache.Key("user_channels", instance.user)) return nearby
def invalidate_cache(cls, sender, instance, *args, **kw): try: cache.delete(cache.Key("user_channels", instance.user)) except User.DoesNotExist: pass
def checkins_clear_cache(sender, instance, **kw): if instance.screening and instance.screening.utc_time: cache.delete(cache.Key("checkins" , instance.screening.utc_time.date(), instance.screening.channel_id))
def clean_instance_cache(self): for kw in self.clean_instance_cache_kwargs(): key = self._create_key(**kw) # logger.debug("clean cache: %r", key, extra={'bg': 'red'}) cache.delete(key)
def make_not_featured(modeladmin, request, queryset): queryset.update(featured=False) cache_key_name = "main_page_activities_all" cache.delete(cache_key_name)
def clear_directors_cache( film ): cache.delete( cache.Key( 'film_directors', film ) )
def invalidate_cache(cls, sender, instance, created, *args, **kw): cache.delete("conversation_thread_%s" % instance.pk) key1 = cache.Key("conversation_unread_counter", instance.sender_id) key2 = cache.Key("conversation_unread_counter", instance.recipient_id) cache.delete(key1) cache.delete(key2)
def invalidate_cache(cls, sender, instance, *args, **kw): cache.delete(cache.Key("user_channels", instance.user_id))
def clear_cache( self ): for size in AVATAR_SIZES: key = cache.Key( "avatar", str(self.user), str(size) ) cache.delete( key )
def checkins_clear_cache(sender, instance, **kw): if instance.screening and instance.screening.utc_time: cache.delete( cache.Key("checkins", instance.screening.utc_time.date(), instance.screening.channel_id))
def post_save(cls, sender, instance, created, *args, **kw): cache.delete(cache.Key("user_basket", instance.user)) if hasattr(instance.user, '_basket'): del instance.user._basket