Closed raviteja1766 closed 4 months ago
It's hard to say what is happening without specifics. I.e. if you are caching a view or a function with cacheops when you need to add language to params or extra. If the query is dependent on selected language then it will be cached under different keys depending on it. Maybe you use some translation lib that rewrites your queries or something. cacheops doesn't know anything about language itself.
So you need to provide more specifics if you are looking for an answer. What are you caching and how? How do you use cacheops? What query are you talking about? Is it cached? Is it varied by language? Do you use any library for translations or is it your code? How do you use that? What do you mean by "active language"?
I am using model level caching here with below config CACHEOPS = { "videos.Video": {"ops": "all"} }
My Model: from django.db import models class Video(models.Model): id = models.CharField( max_length=255, primary_key=True ) name = models.TextField() url = models.TextField() thumbnail_url = models.TextField() dur_in_seconds = models.PositiveIntegerField()
Utils: def activate_language(language: str): from django.utils.translation import activate
if language in Language.get_list_of_values():
language = Language.vernacular_code(language)
activate(language)
def deactivate_language(): from django.utils.translation import deactivate deactivate()
Usecases: If user1 has english language as preference, I activate english language. Fetch the details from query and deactivate again. if user2 has french language as preference, I activate french language. Fetch the details from query and deactivate again. User can also change his preferred language.
Scenario: When user has english language as preference, i am fetching data which will be cached as ( "conj:videos_video:id=fc79b9dc-6992-481b-8fc9-8c0e102c6018" (i noticed this key in my redis-server) ). when user changes his language preference to frech, if i am fetching details now, i am getting cached english details. this is my issue.
I am using django-modeltranslation==0.15.2
Can you look into it please?
conj keys are not cache keys.
I don't know anything about django-modeltranslation, maybe it somehow changes the result of queryset automatically behind the scene. If that is the case you can try setting cache prefix to active language the way it is described here https://github.com/Suor/django-cacheops?tab=readme-ov-file#sharing-redis-instance
conj keys are not cache keys.
I don't know anything about django-modeltranslation, maybe it somehow changes the result of queryset automatically behind the scene. If that is the case you can try setting cache prefix to active language the way it is described here https://github.com/Suor/django-cacheops?tab=readme-ov-file#sharing-redis-instance
django-modeltranslation stores all language-specific fields in the same table adding more columns.
Any update to the entry should result in all language cache prefixes invalidation.
@Suor Is there a way to invalidate multiple cache prefixes at once or any other ideas?
If you'll use cache prefix then still those queries will be invalidated at the same time
вс, 26 мая 2024 г., 17:19 Sridhar @.***>:
conj keys are not cache keys.
I don't know anything about django-modeltranslation, maybe it somehow changes the result of queryset automatically behind the scene. If that is the case you can try setting cache prefix to active language the way it is described here https://github.com/Suor/django-cacheops?tab=readme-ov-file#sharing-redis-instance
django-modeltranslation stores all language-specific fields in the same table adding more columns.
Any update to the entry should result in all language cache prefixes invalidation.
@Suor https://github.com/Suor Is there a way to invalidate multiple cache prefixes at once or any other ideas?
— Reply to this email directly, view it on GitHub https://github.com/Suor/django-cacheops/issues/476#issuecomment-2132166022, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACFLRZY7LUR5CO32YJCOJ3ZEGZMPAVCNFSM6AAAAABIFJIZIGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZSGE3DMMBSGI . You are receiving this because you were mentioned.Message ID: @.***>
When i activate english language, run a query, my query results are cached. Now if i am activating telugu language, runs the same query, i am getting cached results for english, not for telugu.
What i am using here is model level caching.
when i check sql query, its getting all language specific columns, its handling in orm side only, getting actviated language specific fields in defaults.
Expected behaviour when i request for telugu is getting same cached obj only with telugu column fields.