Hello,
I'm currently providing the http://drupal.org/project/apc cache backend project owner a lot of performance and consistency patches. I'm also maintaining the http://drupal.org/project/redis cache backend, and I'm also the maintainer of the http://drupal.org/project/cache_backport module.
There is one thing really bothering me, all along, is that the cache prefix configuration is not unified. I saw that you have this bug opened: #467226: Support for per-bin key prefix.
What I propose is to defined a common cache prefix variable name, and allow a common per-bin cache prefix mecanism all the way, so that every one of those modules would use the same variable for prefixing their cache.
The goal is when an admin configures its cache backends, it doesn't have to configure prefix differently for all of these backends if it uses at least two of them.
What do you think?
I'm not gonna provide any patches here, since it's not about code, but really about find a common variable name and structure for this particular feature, because many cache backends will use it.
@catch For the future, I would really like to see this feature being in core directly in D8 and cache backends totally relieved of this prefix handling. It would be quite easy to do it by proxying the get/set functions via a wrapper factory or using a default implemention on which the backends could rely. This needs some discussion thought.
Comments
Comment #1
pounardI personnally created the $conf['cache_prefix'] variable for Redis.
If we want all to support a per bin prefix, I propose that all modules uses this convention:
The variable 'cache_prefix' is an array or a string. If a string, we use a common prefix for all cache bins.
Example:
If an array, each array key is a bin name, and associated value the associated prefix.
A specific meta bin named 'default' tells default behavior.
Keys can be either a string (prefix name) or FALSE (no prefix forced for this bin).
This behavior is the same for all bins, including the default meta bin.
Example:
Are you OK with this proposal?
Comment #2
Peter Bowey commentedRefer #1
Seems a rather good convention to me!
Can you enlarge on situations for multi-site bins, and the 'default' (where no prefix is forced for a bin)?
Comment #3
catchSounds good, no objections from me.
Comment #4
pounard@catch, nice! I will implement this for Redis and propose a patch for APC. Are you sure my config proposal in #1 fits for Memcache? I'd really like it to be real simple, and maybe create a "official" cache backend documentation file for this that all module would include?
@peter bowey: I'd better say that nothing specified means no prefix at all, I don't care it's dangerous for multisite or not, it's not core related at this point. The goal of making core aware of this is to reach a centralized reliable solution, but right now on D7 it would require API breaking patches. I'm afraid no module can do it on its own without a central API. The way to solve this would be to create a N-th module that would be a dependency for all cache backends, I guess this is not revelant yet until no convention is fixed, and not revelant since most cache backends would not accept to be dependent on this module I guess (more maintenance and design change for all of them at first sight seems a lot to ask).
Comment #5
pounardIf it can help you, I have this algorithm:
I'm using it in Redis backend.
EDIT: Added back the multsite security that was present before.
EDIT (bis): Added the variable being a string support (forgot that the first time).
Comment #6
pounardHere is the documentation I wrote. Please I need a review, any improvement would be nice. I'd really like to see such documentation end up being shared to all backends, so it could be externalized in some drupal.org handbook page and be improved across time for everyone.
Comment #7
mikeytown2 commentedUsing the HTTP_HOST variable isn't ideal. I would use something that uses conf_path() for the default prefix.
If using D7, use drupal_static() instead of static.
Comment #8
mikeytown2 commentedIn terms of use cases I would like to add in multiple prefixes.
so the prefix would be
$_COOKIE, but I would like it to be'example.com' . ':' . $_COOKIE.Some alts
cache_page =
'example.com' . ':' . 'sub-directory' . ':' . $_COOKIE['key_a'] . ':' . $_GET['key_b']cache_bootstrap =
''cache =
'example.com' . ':' . 'sub-directory'One last use case is
cache_menu=
'mine'.I would vote for an array of arrays with the
#globalspecial key as that provides the most flexibly and is fairly easy to maintain a global prefix with cache prefixes as well (a use case I currently have).Comment #9
jason.fisher commentedOld conversation, but I wanted to add that my preferred standard is to use the database name as the prefix. The cache is built from and is unique to that database. If you use Domains, you might want a different operation, but in that case, the segregation should be happening within the cache bin keys.
Comment #10
mikeytown2 commentedUsing the database name as the default sounds like a really good default.
$databases['default']['default']['database']Comment #11
pounardOne note thought: database system is designed to be able to run multiple sites in the same database using table prefixes.
Comment #12
mikeytown2 commentedThink this will work. prefix is defined by default in settings.php
Comment #13
pounardYes, you're right.
Comment #13.0
pounardAdded note about future.
Comment #14
geek-merlinNote: I had live situations where there are same-named databases on different db hosts. So in that case safer:
scheme://user@host/database#prefixNote: no PW.
Comment #15
japerryClosing as Drupal 7 is no longer supported.