D
D
devlly2018-07-26 16:52:22
Django
devlly, 2018-07-26 16:52:22

Why doesn't memcached return values ​​when running workers?

Short description: in django shell memcached returns values, but not in workers.
Detailed:
memcached and celery settings:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
    }
}
CELERY_BROKER_URL = 'amqp://localhost'
CELERY_IGNORE_RESULT = True
CELERY_RESULT_BACKEND = 'cache+memcached://127.0.0.1:11211/'

I'm trying to cache calculations inside a class, it looks like this (nothing unusual, of course):
comp_article = cache.get(url.strip())
if not comp_article:
print('set cache')
comp_article = NewArticle(url=url.strip(), compare=True)
array = comp_article.img_array
title = comp_article.url_title
lang = comp_article.language
val = CacheArticle(array, title, lang)  
 #CacheArticle = namedtuple('CacheArticle', ['img_array', 'url_title', 'language'])
cache.set(url, val, 86400)

then in the virtual environment I start the django server, cache, worker and periodic task :
sudo service memcached start
celery -A anf_man beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
celery -A anf_man worker --concurrency=1 -l info

if you give the task manually without beat - it also does not cache
Help with ideas (ideas, maybe something to read and see in order to understand), what could be wrong, I can’t figure out where to dig, and Google will soon ban!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question