Problems with permanent caching My requirement is to update some params in the script for a some specific nodes. If a set of nodes is attached to an X content type, it should take some params in a script. For this purpose I am running a cron job every 10 min as new contents can be attached to that X content type. In this cron job, I am fetching all nodes belonging to X content type and also from these nodes, I am getting set of nodes attached to each X node. I am storing the corresponding param value for a node in the cache using the function cache_set().

cache_set(node id, X node id, MY_CACHE_NAME, CACHE_PERMANENT)


But the problem is that some nodes are not taking the param sometimes. I think that it is setting the cache, but in the cache table something wrong is happening. But when I run 3 or 4 times the nodes which were not taking param started taking. I am not getting what is happening that cache table.

I am not getting where it is writing to the database. How can we test the problems related to these caching? 

I am clearing the corresponding MYCACHE  before every cron runs.

hook_cron {
  cache_clear_all('*', MY_CACHE, TRUE);
  take_params();
}


What am I doing wrong?
Your use of the functions cache_set() and cache_clear_all() does not look right.

First let us look at cache_set(). It stores some serialized data in some persistent cache bin.

Its arguments are:


$cid - a string that identifies the stored data.  The same string is stored in the $cid field in the database table named by the $bin argument.
$data - the data to cache.  This is stored in the data field identified by $bin and $cid, usually as a serialized object.
$bin - The name (a string)  of the cache bin to use.  This corresponds to a database table with that name.  It should either be 'cache' or start with the string 'cache_'.
$expire - when should the item expire. If set to CACHE_PERMANENT, the item can only be expired by calling cache_clear_all().


You want to cache some parameters attached to some node.  To do that, you may use:

$cid = 'mymodule:node_' . $nid;
$data = ...; // Set it to hold whatever object you want to cache.
$bin = 'cache';
cache_set($cid, $data, $bin, CACHE_PERMANENT);


Note that $bin need to be set to the name of one of the bins (i.e. cache database tables) that are already defined.

Now, to clear out this particular item, you need to call cache_clear_all() with the same $cid and $bin as was you to set the cache.  The final parameter to cache_clear_all() can indicate that $cid is a wildcard (in your case, it is not). I.e.:

cache_clear_all($cid, $bin, FALSE);