Answer the question
In order to leave comments, you need to log in
Django. Can't figure out the cache?
Good day!
Sorry for the stupid question. Faced with the behavior of the cache that is incomprehensible to me. Couldn't google anything.
The point is this.
There is a code that extracts photos from the database:
cacheName = 'photosPage%s' %page
photos = cache.get(cacheName)
if photos == None:
photos = (Thumbs.objects
.filter(pubDate__lte=datetime.now())
.all[:100])
cache.set(cacheName, photos 60 * 10)
for photo in photos:
photo.views += 1
photo.save()
Answer the question
In order to leave comments, you need to log in
You have stored in photos what is received from the cache. Those. you work not handed over from a DB. To increase the counter, you need to access the database.
The operation of the counter during rebuilding is due precisely to the fact that at this moment information is stored there for working with the database.
cache.get(cacheName) != Thumbs.objects.filter(pubDate__lte=datetime.now()).all[:100]
It's better to increment the counter in memory and drop it periodically in the database.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question