get($cid); $mess = $ret ? "HIT" : "MISS"; drush_log(dt("Cache !mess cid: !cid", array('!mess' => $mess, '!cid' => $cid)), LogLevel::DEBUG); return $ret; } /** * Return data from the persistent cache when given an array of cache IDs. * * @param array $cids * An array of cache IDs for the data to retrieve. This is passed by * reference, and will have the IDs successfully returned from cache removed. * @param string $bin * The cache bin where the data is stored. * * @return * An array of the items successfully returned from cache indexed by cid. */ function drush_cache_get_multiple(array &$cids, $bin = 'default') { return _drush_cache_get_object($bin)->getMultiple($cids); } /** * Store data in the persistent cache. * * @param string $cid * The cache ID of the data to store. * * @param $data * The data to store in the cache. * @param string $bin * The cache bin to store the data in. * @param $expire * One of the following values: * - DRUSH_CACHE_PERMANENT: Indicates that the item should never be removed * unless explicitly told to using drush_cache_clear_all() with a cache ID. * - DRUSH_CACHE_TEMPORARY: Indicates that the item should be removed at * the next general cache wipe. * - A Unix timestamp: Indicates that the item should be kept at least until * the given time, after which it behaves like DRUSH_CACHE_TEMPORARY. * * @return bool */ function drush_cache_set($cid, $data, $bin = 'default', $expire = DRUSH_CACHE_PERMANENT) { $ret = _drush_cache_get_object($bin)->set($cid, $data, $expire); if ($ret) drush_log(dt("Cache SET cid: !cid", array('!cid' => $cid)), LogLevel::DEBUG); return $ret; } /** * Expire data from the cache. * * If called without arguments, expirable entries will be cleared from all known * cache bins. * * @param string $cid * If set, the cache ID to delete. Otherwise, all cache entries that can * expire are deleted. * @param string $bin * If set, the bin $bin to delete from. Mandatory * argument if $cid is set. * @param bool $wildcard * If $wildcard is TRUE, cache IDs starting with $cid are deleted in * addition to the exact cache ID specified by $cid. If $wildcard is * TRUE and $cid is '*' then the entire bin $bin is emptied. */ function drush_cache_clear_all($cid = NULL, $bin = 'default', $wildcard = FALSE) { if (!isset($cid) && !isset($bin)) { foreach (drush_cache_get_bins() as $bin) { _drush_cache_get_object($bin)->clear(); } return; } return _drush_cache_get_object($bin)->clear($cid, $wildcard); } /** * Check if a cache bin is empty. * * A cache bin is considered empty if it does not contain any valid data for any * cache ID. * * @param $bin * The cache bin to check. * * @return * TRUE if the cache bin specified is empty. */ function _drush_cache_is_empty($bin) { return _drush_cache_get_object($bin)->isEmpty(); } /** * Return drush cache bins and any bins added by hook_drush_flush_caches(). */ function drush_cache_get_bins() { $drush = array('default'); return array_merge(drush_command_invoke_all('drush_flush_caches'), $drush); } /** * Create a cache id from a given prefix, contexts, and additional parameters. * * @param prefix * A human readable cid prefix that will not be hashed. * @param contexts * Array of drush contexts that will be used to build a unique hash. * @param params * Array of any addition parameters to be hashed. * * @return * A cache id string. */ function drush_get_cid($prefix, $contexts = array(), $params = array()) { $cid = array(); foreach ($contexts as $context) { $c = drush_get_context($context); if (!empty($c)) { $cid[] = is_scalar($c) ? $c : serialize($c); } } foreach ($params as $param) { $cid[] = $param; } return DRUSH_VERSION . '-' . $prefix . '-' . md5(implode("", $cid)); }