Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master-Replica databases result in multiple cached entities. #135

Open
langal opened this issue Aug 15, 2019 · 0 comments
Open

Master-Replica databases result in multiple cached entities. #135

langal opened this issue Aug 15, 2019 · 0 comments

Comments

@langal
Copy link

langal commented Aug 15, 2019

If we have both a master and replica database configured, cachalot uses separate database aliases as part of the cache key.

This results in the same "data"being cached twice.

It also makes cache invalidation trickier as we have to invalidate multiple cached entries.

langal added a commit to langal/django-cachalot that referenced this issue Aug 15, 2019
noripyt#135

Have the table key generation look for a "CACHE_KEY" configuration in the Django DATABASES configs.

If a "CACHE_KEY" value is found, then we use that instead of the "db_alias".

This allows us to synch Master and Replicas to use the same key namespace to prevent "double-caching" and the need to invalidate 2 cache entries upon an update.

The Django configuration would look like:

DATABASES = {
    'master': {
        'CACHE_KEY': 'WE_ARE_ONE',
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': DB_NAME,
        'USER': DB_USER,
        'PASSWORD': DB_PASSWORD,
        'HOST': DB_HOST,
        'PORT': DB_PORT,
        'OPTIONS': {
            'client_encoding': "UTF8"
        }
    },
    'replica' : {
        'CACHE_KEY': 'WE_ARE_ONE',
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': DB_NAME,
        'USER': DB_USER,
        'PASSWORD': DB_PASSWORD,
        'HOST': DB_HOST,
        'PORT': DB_PORT,
        'OPTIONS': {
            'client_encoding': "UTF8"
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant