2

For using cache_get and cache_set

According to this comment

The convention seems to be to use colons to create a sort of namespacing. So your module may want to do something like $cid = 'mymodule:mything:50';

so:

  • is ':' the recommended delimiter?
  • should the module name go first? (seems sensible)?
  • are there characters to avoid?
  • are there other considerations?
3
  1. is ':' the recommended delimiter? I haven't heard that : is recommended over anything else, but since it's definitely used all over core, it would make a lot of sense. All cache backends that work with Drupal will be handling : well.

  2. should the module name go first? (seems sensible)? Yes, this is general practice, not just cache keys.

  3. are there characters to avoid? None that I've heard of. In general, in 2013, if any system doesn't properly handle any character in a string properly, I would find really bad to be honest. With that said, we'll always be dealing with one form or another of legacy software. So stick to a-z, numbers and : if you're feeling risk averse.

  4. are there other considerations? Can't immediately think of any.

1
  • thanks! re 4. - one factor is that cache clearing is done on the initial part of the key, so worth considering any cache clearing functionality that you may need. Oct 23 '13 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.