2
Yes, you have the right idea. The general principle is that your cache key needs to be different for each query that might produce different results. Here, your query does only depend on creationdate
and request.user
, so as long as both of those are in the key then you’re set.
However, you also need to make sure that the keys you generate for this function’s use of the cache are different from keys used by other parts of your Django deployment. So you should also include some kind of namespace. For example, something resembling this:
"per-day-entries-{0}-{1}".format(request.user.username, creationdate)
Source:stackexchange.com