Comments (11)
Yes, you're right. I already wanted to add multi-database support.
After that, don’t you think adding a CACHALOT_CACHE_PREFIX
setting could be enough?
The resulting cache keys would have the form:
'%s:%s:%s:queries' % (prefix, using, table_name)
from django-cachalot.
I'm afraid not. I think CACHALOT_CACHE_PREFIX
is a setting and will be applied to the whole project. There are times when you want to store data in separate schemas in the same database. All the schemas would share the setting. See http://www.postgresql.org/docs/9.1/static/ddl-schemas.html
One example of django SaaS framework is https://github.com/bernardopires/django-tenant-schemas There are many more that basically do the same thing. They tie the subdomain of the URL to a postgesql schema. So if the current request was pointed at github.myservice.com, then github schema will be used to execute queries in instead of the default public schema. This is a more common usecase than most people think.
The problem is that it happens are runtime while the setting is defined when django boots up. There needs to be a way to change the cache key per http request or even be able to explicitly change the cache key per query.
May be cachalot can provide a class called CachalotAdapter
and this class can have some methods that can be overriden for example,
class CachealotAdapter(BaseCachalotAdapter):
def get_cache_key(self, queryset):
pass
or
class CachealotAdapter(BaseCachalotAdapter):
def get_cache_key(self, connection):
pass
The default adapter shipped can have it's cache key logic in that method but users can subclass the default adapter and point to the custom adapter in settings like
CACHALOT_ADAPTER = 'myproject.adapters.CachalotAdapter'
The method to fetch cache key can get all the relevant info as parameters like the database in user, queryset, db connection instance or whatever makes sense.
from django-cachalot.
OK, I understand. I didn't know django-tenant-schemas.
Your solution is obviously the right approach. That's the kind of class override I wanted to add for memcached, as it needs cache keys to be hashed when exceeding 255 characters.
I'll implement this before Cachalot 1.0 :)
from django-cachalot.
@BertrandBordage Awesome! Really looking forward to using cachalot. Let me know if you need any help with testing this or even implementing.
from django-cachalot.
When that feature will be ready, I will ask you to test it on your installation, and we will add the overridden class to the docs as a tip for people using django-tenant-schemas.
from django-cachalot.
Fixed in 83618b6.
Can you customize the 2 key generators used by django-cachalot for django-tenant-schemas compatibility? You have to customize these functions and point to your versions using these settings. I quickly read django-tenant-schemas and you probably need to use attributes like connection.schema_name
.
I’ll then make a release candidate for version 1.0.
from django-cachalot.
Yes, I think that should work. Thanks!
from django-cachalot.
Great! I also added docstrings to explain what the arguments of these functions are.
Are you trying to make django-cachalot work with django-tenant-schemas?
If so, we can add a note in the docs about this before version 1.0.
from django-cachalot.
I'm not trying to set it up just yet but will probably do that in the upcoming weeks. I don't think cachealot needs any special mention for any special apps. I think tenant schemas should mention this as a warning for using cache systems.
from django-cachalot.
I want cachalot to be a simple and reliable tool, so compatibity notes are welcome, even if they’re redundant with what’s written in 3rd-party app docs.
So feel free to send a pull request if you want.
from django-cachalot.
Got it. Refreshing approach to open source apps. Usually authors one github are very uptight. I'll setup cachalot in the coming weeks and create a PR to update docs (and anything else if needed) at that time.
Thanks again.
from django-cachalot.
Related Issues (20)
- Does not support Django 4.1 HOT 3
- Allow enum-likes in CACHABLE_PARAM_TYPES HOT 1
- Tables defined in CACHALOT_UNCACHABLE_APPS are still being cached
- UncachableQuery raised when exporting models of table even if listed in `CACHALOT_UNCACHABLE_APPS`. HOT 3
- Does django-cachalot lib support the new django.core.cache.backends.redis.RedisCache cache backend in Django version 4.0? HOT 4
- using override_settings(CACHALOT_ENABLED=False) has no effect HOT 2
- Using timestamps considered harmful HOT 2
- NoneType error when saving UserProfileAdmin after Django 4.1 update
- Support Django 4.2
- Docs are not getting rendered correctly
- Update records after bulk_update many objects
- Is there a recommended way to turn off cachalot on a production DB without any downtime? HOT 2
- Why is my cache not invalidated? HOT 1
- Msssql future support HOT 2
- Cachalot tries to create a database connection on import HOT 4
- If redis is unavailable during migration, migration is applied but not inserted into migration table.
- Patched cursor does not expect psycopg2 sql Composed Object HOT 4
- Django 5 support HOT 2
- Renew timeout when query is accessed via cache
- Query which filters on annotation of second query does not have cache invalidated HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-cachalot.