Git Product home page Git Product logo

Comments (11)

BertrandBordage avatar BertrandBordage commented on June 15, 2024

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.

owais avatar owais commented on June 15, 2024

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.

BertrandBordage avatar BertrandBordage commented on June 15, 2024

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.

owais avatar owais commented on June 15, 2024

@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.

BertrandBordage avatar BertrandBordage commented on June 15, 2024

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.

BertrandBordage avatar BertrandBordage commented on June 15, 2024

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.

owais avatar owais commented on June 15, 2024

Yes, I think that should work. Thanks!

from django-cachalot.

BertrandBordage avatar BertrandBordage commented on June 15, 2024

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.

owais avatar owais commented on June 15, 2024

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.

BertrandBordage avatar BertrandBordage commented on June 15, 2024

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.

owais avatar owais commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.