Problem/Motivation

When try to cache_clear_all with $cid, but no $bin, no effect. The reason is the cache key is generated by $bin . '-' . $cid (e.g cache-foo) and since there is no bin details, the key become something like '-foo'. This details is in the docblock, of cache_clear_all, but code doesn't enforce it.

/**
 * Expires data from the cache.
...
...
 * @param $bin
 *   If set, the cache bin to delete from. Mandatory argument if $cid is set.
...
...
 */
function cache_clear_all($cid = NULL, $bin = NULL, $wildcard = FALSE) {

Proposed resolution

Solution 1. Provide default option to bin, if $cid is set.
Solution 2. If solution 1 is too much assumption, throw an exception for the calls with $cid and no $bin.

Remaining tasks

1. Discuss
2. Issue path

User interface changes

N/A

API changes

Depends on solution.

CommentFileSizeAuthor
#2 2189537-cache-no-bin-2.patch516 bytesvijaycs85
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vijaycs85’s picture

vijaycs85’s picture

Title: Fail gracefully if no bin for cache_clear_all » Fail gracefully if no bin for cache_clear_all, but cid is set
FileSize
516 bytes
vijaycs85’s picture

Status: Active » Needs review
vijaycs85’s picture

Issue summary: View changes
danblack’s picture

Status: Needs review » Reviewed & tested by the community

looks good!

David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs work

Seems reasonable, since the current behavior is an unhelpful-looking PDOException anyway.

However, "\Exception" (with the forward-slash namespace thing) won't work on PHP 5.2, right?

And the exception message should really be a complete sentence.