def model_post_save_callback(sender, instance, created, raw, using, update_fields, **kwargs): clearcache = False if isinstance(instance, LogEntry): return if 'get_full_url' in dir(instance): is_update_views = update_fields == {'views'} if not settings.TESTING and not is_update_views: try: notify_url = instance.get_full_url() SpiderNotify.baidu_notify([notify_url]) except Exception as ex: logger.error("notify sipder", ex) if not is_update_views: clearcache = True if isinstance(instance, Comment): path = instance.article.get_absolute_url() site = get_current_site().domain if site.find(':') > 0: site = site[0:site.find(':')] expire_view_cache(path, servername=site, serverport=80, key_prefix='blogdetail') if cache.get('seo_processor'): cache.delete('seo_processor') comment_cache_key = 'article_comments_{id}'.format(id=instance.article.id) cache.delete(comment_cache_key) delete_sidebar_cache(instance.author.username) delete_view_cache('article_comments', [str(instance.article.pk)]) _thread.start_new(send_comment_email, (instance,)) if clearcache: cache.clear()
def handle(self, *args, **options): user = \ get_user_model().objects.get_or_create(email='*****@*****.**', username='******', password='******')[0] pcategory = Category.objects.get_or_create(name='我是父类目', parent_category=None)[0] category = Category.objects.get_or_create(name='子类目', parent_category=pcategory)[0] category.save() basetag = Tag() basetag.name = "标签" basetag.save() for i in range(1, 20): article = Article.objects.get_or_create( category=category, title='nice title ' + str(i), body='nice content ' + str(i), author=user)[0] tag = Tag() tag.name = "标签" + str(i) tag.save() article.tags.add(tag) article.tags.add(basetag) article.save() from agrosite.utils import cache cache.clear() self.stdout.write(self.style.SUCCESS('created test datas \n'))
def refresh_memcache(request): try: if request.user.is_superuser: from agrosite.utils import cache if cache and cache is not None: cache.clear() return HttpResponse("ok") else: return HttpResponseForbidden() except Exception as e: logger.error(e) return HttpResponse(e)
def form_valid(self, form): form = AuthenticationForm(data=self.request.POST, request=self.request) if form.is_valid(): from agrosite.utils import cache if cache and cache is not None: cache.clear() logger.info(self.redirect_field_name) auth.login(self.request, form.get_user()) return super(LoginView, self).form_valid(form) # return HttpResponseRedirect('/') else: return self.render_to_response({ 'form': form })
def save(self, *args, **kwargs): super().save(*args, **kwargs) from agrosite.utils import cache cache.clear()
def get(self, request, *args, **kwargs): from agrosite.utils import cache cache.clear() logout(request) return super(LogoutView, self).get(request, *args, **kwargs)
def user_auth_callback(sender, request, user, **kwargs): if user and user.username: logger.info(user) delete_sidebar_cache(user.username) cache.clear()
def handle(self, *args, **options): cache.clear() self.stdout.write(self.style.SUCCESS('Cleared cache\n'))