From bd46f663ae6e427f828d543932b7b33ff0c594df Mon Sep 17 00:00:00 2001 From: Moshe Weitzman Date: Fri, 31 Dec 2021 15:05:58 -0500 Subject: [PATCH] More deletion --- src/Cache/CacheInterface.php | 114 ------------------ src/Cache/CommandCache.php | 64 ---------- src/Cache/FileCache.php | 175 ---------------------------- src/Cache/JSONCache.php | 32 ----- src/Commands/core/CacheCommands.php | 3 +- 5 files changed, 1 insertion(+), 387 deletions(-) delete mode 100644 src/Cache/CacheInterface.php delete mode 100644 src/Cache/CommandCache.php delete mode 100644 src/Cache/FileCache.php delete mode 100644 src/Cache/JSONCache.php diff --git a/src/Cache/CacheInterface.php b/src/Cache/CacheInterface.php deleted file mode 100644 index 5cf54469e9..0000000000 --- a/src/Cache/CacheInterface.php +++ /dev/null @@ -1,114 +0,0 @@ -cacheBackend = $cacheBackend; - } - - /** - * Test for an entry from the cache - * @param string $key - * @return boolean - */ - public function has($key) - { - $cacheItem = $this->cacheBackend->get($key); - return $this->valid($cacheItem); - } - /** - * Get an entry from the cache - * @param string $key - * @return array - */ - public function get($key) - { - $cacheItem = $this->cacheBackend->get($key); - if (!$this->valid($cacheItem)) { - return []; - } - // TODO: FileCache::get() should just return the - // data element, not the entire cacheItem. Then we - // could make it implement SimpleCacheInterface & do - // away with this adapter class. - return $cacheItem->data; - } - /** - * Store an entry in the cache - * @param string $key - * @param array $data - */ - public function set($key, $data) - { - $this->cacheBackend->set($key, $data); - } - - protected function valid($cacheItem) - { - return is_object($cacheItem) && isset($cacheItem->data); - } -} diff --git a/src/Cache/FileCache.php b/src/Cache/FileCache.php deleted file mode 100644 index 848fdd6f70..0000000000 --- a/src/Cache/FileCache.php +++ /dev/null @@ -1,175 +0,0 @@ -bin = $bin; - $this->directory = $this->cacheDirectory(); - } - - /** - * Returns the cache directory for the given bin. - * - * @param string $bin - */ - public function cacheDirectory($bin = null) - { - $bin = $bin ? $bin : $this->bin; - return Path::join(Drush::config()->cache(), $bin); - } - - public function get($cid) - { - $cids = [$cid]; - $cache = $this->getMultiple($cids); - return reset($cache); - } - - public function getMultiple(&$cids) - { - try { - $cache = []; - foreach ($cids as $cid) { - $filename = $this->getFilePath($cid); - if (!file_exists($filename)) { - return []; - } - - $item = $this->readFile($filename); - if ($item) { - $cache[$cid] = $item; - } - } - $cids = array_diff($cids, array_keys($cache)); - return $cache; - } catch (\Exception $e) { - return []; - } - } - - /** - * Returns the contents of the given filename unserialized. - * - * @param string $filename - * Absolute path to filename to read contents from. - */ - public function readFile($filename) - { - $item = file_get_contents($filename); - return $item ? unserialize($item) : false; - } - - public function set($cid, $data, $expire = DRUSH_CACHE_PERMANENT) - { - $created = time(); - - $cache = new \stdClass; - $cache->cid = $cid; - $cache->data = is_object($data) ? clone $data : $data; - $cache->created = $created; - if ($expire == DRUSH_CACHE_TEMPORARY) { - $cache->expire = $created + 2591999; - } elseif ($expire != DRUSH_CACHE_PERMANENT && $expire < 2592000) { - // Expire time is in seconds if less than 30 days, otherwise is a timestamp. - $cache->expire = $created + $expire; - } else { - $cache->expire = $expire; - } - - // Ensure the cache directory still exists, in case a backend process - // cleared the cache after the cache was initialized. - $fs = new Filesystem(); - $fs->mkdir($this->directory); - - $filename = $this->getFilePath($cid); - return $this->writeFile($filename, $cache); - } - - /** - * Serializes data and write it to the given filename. - * - * @param string $filename - * Absolute path to filename to write cache data. - * @param $cache - * Cache data to serialize and write to $filename. - */ - public function writeFile($filename, $cache) - { - return file_put_contents($filename, serialize($cache)); - } - - public function clear($cid = null, $wildcard = false) - { - $fs = new Filesystem(); - $bin_dir = $this->cacheDirectory(); - $files = []; - if (empty($cid)) { - $fs->remove($bin_dir); - } else { - if ($wildcard) { - if ($cid == '*') { - $fs->remove($bin_dir); - } else { - $files = Finder::create() - ->files() - ->name($cid) - ->in($bin_dir); - } - } else { - $files[] = $this->getFilePath($cid); - } - - $fs->remove($files); - } - } - - public function isEmpty() - { - $files = Finder::create() - ->files() - ->name() - ->exclude() - ->depth(0) - ->in($this->directory); - return empty($files); - } - - /** - * Converts a cache id to a full path. - * - * @param $cid - * The cache ID of the data to retrieve. - * - * @return - * The full path to the cache file. - */ - protected function getFilePath($cid) - { - return $this->directory . '/' . str_replace([':', '\\', '/'], '.', $cid) . self::EXTENSION; - } -} diff --git a/src/Cache/JSONCache.php b/src/Cache/JSONCache.php deleted file mode 100644 index 5f5c8ffd97..0000000000 --- a/src/Cache/JSONCache.php +++ /dev/null @@ -1,32 +0,0 @@ - and &, so we do it with str_replace(). - $json = str_replace(['<', '>', '&'], ['\u003c', '\u003e', '\u0026'], $json); - return file_put_contents($filename, $json); - } -} diff --git a/src/Commands/core/CacheCommands.php b/src/Commands/core/CacheCommands.php index 413ac5009c..b80548af59 100644 --- a/src/Commands/core/CacheCommands.php +++ b/src/Commands/core/CacheCommands.php @@ -300,8 +300,7 @@ public function getTypes($include_bootstrapped_types = false): array public static function clearDrush(): void { try { - drush_cache_clear_all(null, 'default');// No longer used by Drush core, but still cleared for backward compat. - drush_cache_clear_all(null, 'factory'); // command info from annotated-command library (i.e. parsed annotations) + // No longer anything to do here. Left because some commandfiles may try to call this. } catch (IOException $e) { // Sometimes another process writes files into a bin dir and \Drush\Cache\FileCache::clear fails. // That is not considered an error. https://github.com/drush-ops/drush/pull/4535.