Example #1
0
 public function clear($key = null)
 {
     // return true if the cache is already empty
     if (!($driver = $this->getDriver())) {
         return true;
     }
     if (!isset($key)) {
         unset($driver);
         $this->driver = null;
         $this->driver = false;
         ehough_stash_Utilities::deleteRecursive($this->path);
     } else {
         $driver->query("DELETE FROM cacheStore WHERE key LIKE '{$key}%'");
     }
     return true;
 }
Example #2
0
 /**
  * Finds the method of encoding that has the cheapest decode needs and encodes the data with that method.
  *
  * @param  string $data
  * @return string
  */
 protected function encode($data)
 {
     switch (ehough_stash_Utilities::encoding($data)) {
         case 'bool':
             $dataString = (bool) $data ? 'true' : 'false';
             break;
         case 'serialize':
             $dataString = 'unserialize(base64_decode(\'' . base64_encode(serialize($data)) . '\'))';
             break;
         case 'string':
             $dataString = sprintf('"%s"', addcslashes($data, "\t\"\$\\"));
             break;
         case 'none':
         default:
             if (is_numeric($data)) {
                 $dataString = (string) $data;
             } else {
                 $dataString = 'base64_decode(\'' . base64_encode($data) . '\')';
             }
             break;
     }
     return $dataString;
 }
Example #3
0
 /**
  * This function takes an array of strings and turns it into the sqlKey. It does this by iterating through the
  * array, running the string through sqlite_escape_string() and then combining that string to the keystring with a
  * delimiter.
  *
  * @param  array  $key
  * @return string
  */
 public static function makeSqlKey($key)
 {
     $key = ehough_stash_Utilities::normalizeKeys($key, 'base64_encode');
     $path = '';
     foreach ($key as $rawPathPiece) {
         $path .= $rawPathPiece . ':::';
     }
     return $path;
 }
 /**
  * This function clears the data from a key. If a key points to both a directory and a file, both are erased. If
  * passed null, the entire cache directory is removed.
  *
  * @param  null|array $key
  * @return bool
  */
 public function clear($key = null)
 {
     $path = $this->makePath($key);
     if (is_file($path)) {
         $return = true;
         unlink($path);
     }
     if (strpos($path, '.php') !== false) {
         $path = substr($path, 0, -4);
     }
     if (is_dir($path)) {
         return ehough_stash_Utilities::deleteRecursive($path);
     }
     return isset($return);
 }
Example #5
0
 public static function tearDownAfterClass()
 {
     ehough_stash_Utilities::deleteRecursive(ehough_stash_Utilities::getBaseDirectory());
 }
Example #6
0
 public function testCheckEmptyDirectory()
 {
     $tmp = sys_get_temp_dir() . '/stash/';
     $dir2 = $tmp . 'emptytest/';
     @mkdir($dir2, 0770, true);
     $this->assertTrue(ehough_stash_Utilities::checkForEmptyDirectory($dir2), 'Returns true for empty directories');
     $this->assertFalse(ehough_stash_Utilities::checkForEmptyDirectory($tmp), 'Returns false for non-empty directories');
     ehough_stash_Utilities::deleteRecursive($tmp);
 }
Example #7
0
 /**
  * Turns a key array into a key string. This includes running the indexing functions used to manage the Redis
  * hierarchical storage.
  *
  * When requested the actual path, rather than a normalized value, is returned.
  *
  * @param  array  $key
  * @param  bool   $path
  * @return string
  */
 protected function makeKeyString($key, $path = false)
 {
     $key = ehough_stash_Utilities::normalizeKeys($key);
     $keyString = 'cache:::';
     $pathKey = ':pathdb::';
     foreach ($key as $name) {
         //a. cache:::name
         //b. cache:::name0:::sub
         $keyString .= $name;
         //a. :pathdb::cache:::name
         //b. :pathdb::cache:::name0:::sub
         $pathKey = ':pathdb::' . $keyString;
         $pathKey = md5($pathKey);
         if (isset($this->keyCache[$pathKey])) {
             $index = $this->keyCache[$pathKey];
         } else {
             $index = $this->redis->get($pathKey);
             $this->keyCache[$pathKey] = $index;
         }
         //a. cache:::name0:::
         //b. cache:::name0:::sub1:::
         $keyString .= '_' . $index . ':::';
     }
     return $path ? $pathKey : md5($keyString);
 }
Example #8
0
 /**
  * Turns a key array into a key string. This includes running the indexing functions used to manage the memcached
  * hierarchical storage.
  *
  * When requested the actual path, rather than a normalized value, is returned.
  *
  * @param  array  $key
  * @param  bool   $path
  * @return string
  */
 protected function makeKeyString($key, $path = false)
 {
     $key = ehough_stash_Utilities::normalizeKeys($key);
     $keyString = ':cache:::';
     $pathKey = ':pathdb::';
     $time = microtime(true);
     if ($time - $this->keyCacheTime >= $this->keyCacheTimeLimit) {
         $this->keyCacheTime = $time;
         $this->keyCache = array();
     }
     foreach ($key as $name) {
         //a. cache:::name
         //b. cache:::name0:::sub
         $keyString .= $name;
         //a. :pathdb::cache:::name
         //b. :pathdb::cache:::name0:::sub
         $pathKey = ':pathdb::' . $keyString;
         $pathKey = md5($pathKey);
         if (isset($this->keyCache[$pathKey])) {
             $index = $this->keyCache[$pathKey];
         } else {
             $index = $this->memcache->cas($pathKey, 0);
             $this->keyCache[$pathKey] = $index;
         }
         //a. cache:::name0:::
         //b. cache:::name0:::sub1:::
         $keyString .= '_' . $index . ':::';
     }
     return $path ? $pathKey : md5($keyString);
 }
Example #9
0
 /**
  * This function clears the data from a key. If a key points to both a directory and a file, both are erased. If
  * passed null, the entire cache directory is removed.
  *
  * {@inheritdoc}
  */
 public function clear($key = null)
 {
     $path = $this->makePath($key);
     if (is_file($path)) {
         $return = true;
         unlink($path);
     }
     $extension = $this->getEncoder()->getExtension();
     if (strpos($path, $extension) !== false) {
         $path = substr($path, 0, -strlen($extension));
     }
     if (is_dir($path)) {
         return ehough_stash_Utilities::deleteRecursive($path, true);
     }
     return isset($return);
 }