Example #1
0
 /**
  * Clear cache
  */
 public function clearCache()
 {
     $tag = CM_Cache_Shared::getInstance()->key(CM_CacheConst::PagingSource, $this->_cacheKeyBase());
     if ($this->_cache) {
         $this->_cache->deleteTag($tag);
     }
 }
Example #2
0
 public function isValid($email)
 {
     $email = (string) $email;
     if (false === filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return false;
     }
     $key = __METHOD__ . '_email:' . $email . '_invalid:' . $this->_disallowInvalid . '_disposable:' . $this->_disallowDisposable . '_threshold:' . $this->_disallowUnknownThreshold;
     $cache = CM_Cache_Shared::getInstance();
     if (false === ($isValid = $cache->get($key))) {
         $response = $this->_getResponseBody($email);
         if (null === $response) {
             return true;
         }
         $isInvalid = isset($response['result']) && 'invalid' === $response['result'];
         $isDisposable = isset($response['disposable']) && true === $response['disposable'];
         $isSendexUnderThreshold = isset($response['sendex']) && $response['sendex'] < $this->_disallowUnknownThreshold;
         $isUnknown = isset($response['result']) && 'unknown' === $response['result'] || isset($response['accept_all']) && true === $response['accept_all'];
         if ($this->_disallowInvalid && $isInvalid || $this->_disallowDisposable && $isDisposable || $isSendexUnderThreshold && $isUnknown) {
             $isValid = 0;
         } else {
             $isValid = 1;
         }
         $cache->set($key, $isValid);
     }
     return (bool) $isValid;
 }
Example #3
0
 public function testSave()
 {
     $id1 = 1;
     $cacheKey1 = 'CM_Model_StorageAdapter_Cache_type:1_id:a:1:{s:2:"id";i:1;}';
     CM_Cache_Shared::getInstance()->set($cacheKey1, array('foo' => 'foo1', 'bar' => $id1));
     $id2 = 2;
     $cacheKey2 = 'CM_Model_StorageAdapter_Cache_type:1_id:a:1:{s:2:"id";i:2;}';
     CM_Cache_Shared::getInstance()->set($cacheKey2, array('foo' => 'foo2', 'bar' => $id2));
     $type = 1;
     $adapter = new CM_Model_StorageAdapter_Cache();
     $adapter->save($type, array('id' => $id1), array('foo' => 'hello', 'bar' => 55));
     $this->assertSame(array('foo' => 'hello', 'bar' => 55), CM_Cache_Shared::getInstance()->get($cacheKey1));
     $this->assertSame(array('foo' => 'foo2', 'bar' => 2), CM_Cache_Shared::getInstance()->get($cacheKey2));
 }
Example #4
0
 public function testCache()
 {
     $source = new CM_PagingSource_Sql('`num`', 'test');
     $source->enableCache();
     $this->assertSame(100, $source->getCount());
     $sourceNocache = new CM_PagingSource_Sql('`num`', 'test');
     $this->assertSame(100, $sourceNocache->getCount());
     CM_Db_Db::delete('test', array('num' => 0));
     $this->assertSame(100, $source->getCount());
     $this->assertSame(99, $sourceNocache->getCount());
     $source->clearCache();
     $this->assertSame(99, $source->getCount());
     $this->assertSame(99, $sourceNocache->getCount());
     CM_Cache_Shared::getInstance()->flush();
 }
Example #5
0
 protected function _cacheGet($key)
 {
     $tag = CM_Cache_Shared::getInstance()->key(CM_CacheConst::PagingSource, $this->_cacheKeyBase());
     $key = CM_Cache_Shared::getInstance()->key(CM_CacheConst::PagingSource, $key);
     if ($this->_cacheLocalLifetime) {
         if (($result = CM_Cache_Local::getInstance()->getTagged($tag, $key)) !== false) {
             return $result;
         }
     }
     if ($this->_cacheLifetime) {
         if (($result = CM_Cache_Shared::getInstance()->getTagged($tag, $key)) !== false) {
             return $result;
         }
     }
     return false;
 }
Example #6
0
 /**
  * @return string
  */
 private function _toRegex()
 {
     $cacheKey = CM_CacheConst::ContentList_BadwordRegex;
     $cache = CM_Cache_Shared::getInstance();
     if (false == ($badwordsRegex = $cache->get($cacheKey))) {
         if ($this->isEmpty()) {
             $badwordsRegex = '#\\z.#';
         } else {
             $regexList = array();
             foreach ($this as $badword) {
                 $regexList[] = $this->_transformItemToRegex($badword);
             }
             $badwordsRegex = '#(?:' . implode('|', $regexList) . ')#i';
         }
         $cache->set($cacheKey, $badwordsRegex);
     }
     return $badwordsRegex;
 }
Example #7
0
 public function testFindByKeyAndAdapter()
 {
     $adapterType = 1;
     /** @var CM_Model_StreamChannel_Media $streamChannelOriginal */
     $streamChannelOriginal = CMTest_TH::createStreamChannel(null, $adapterType);
     $streamChannelId = $streamChannelOriginal->getId();
     $streamChannelKey = $streamChannelOriginal->getKey();
     $streamChannel = CM_Model_StreamChannel_Abstract::findByKeyAndAdapter($streamChannelKey, $adapterType);
     $this->assertInstanceOf('CM_Model_StreamChannel_Media', $streamChannel);
     $this->assertEquals($streamChannelOriginal->getId(), $streamChannel->getId());
     $streamChannelOriginal->delete();
     $this->assertNull(CM_Model_StreamChannel_Abstract::findByKeyAndAdapter($streamChannelKey, $adapterType));
     // invalid cache-entry
     $cacheKey = CM_CacheConst::StreamChannel_Id . '_key' . $streamChannelKey . '_adapterType:' . $adapterType;
     $cache = CM_Cache_Shared::getInstance();
     $cache->set($cacheKey, ['id' => $streamChannelId, 'type' => $adapterType]);
     $this->assertNull(CM_Model_StreamChannel_Abstract::findByKeyAndAdapter($streamChannelKey, $adapterType));
     $this->assertSame(false, $cache->get($cacheKey));
 }
Example #8
0
 public function isValid($email)
 {
     $email = (string) $email;
     if (false === filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return false;
     }
     $key = __METHOD__ . '_email:' . $email;
     $cache = CM_Cache_Shared::getInstance();
     if (false === ($isValid = $cache->get($key))) {
         $response = $this->_getResponseBody($email);
         if (null === $response) {
             return true;
         }
         if (!isset($response['status']) || 'invalid' === $response['status'] || 'bad_data' === $response['status']) {
             $isValid = 0;
         } else {
             $isValid = 1;
         }
         $cache->set($key, $isValid);
     }
     return (bool) $isValid;
 }
Example #9
0
 /**
  * @param string $id
  * @return array|null
  */
 private static function _findDataById($id)
 {
     $cacheKey = self::_getCacheKey($id);
     $cache = CM_Cache_Shared::getInstance();
     if (($data = $cache->get($cacheKey)) === false) {
         $data = CM_Db_Db::select('cm_session', array('data', 'expires'), array('sessionId' => $id))->fetch();
         if (!$data) {
             return null;
         }
         $cache->set($cacheKey, $data, self::LIFETIME_DEFAULT);
     }
     return $data;
 }
Example #10
0
 /**
  * @param Closure|null $callbackBefore fn($version)
  * @param Closure|null $callbackAfter fn($version)
  * @return int Number of version bumps
  */
 public function runUpdateScripts(Closure $callbackBefore = null, Closure $callbackAfter = null)
 {
     CM_Cache_Shared::getInstance()->flush();
     CM_Cache_Local::getInstance()->flush();
     $versionBumps = 0;
     foreach ($this->getUpdateScriptPaths() as $namespace => $path) {
         $version = $versionStart = $this->getVersion($namespace);
         while (true) {
             $version++;
             if (!$this->runUpdateScript($namespace, $version, $callbackBefore, $callbackAfter)) {
                 $version--;
                 break;
             }
             $this->setVersion($version, $namespace);
         }
         $versionBumps += $version - $versionStart;
     }
     if ($versionBumps > 0) {
         $db = $this->getServiceManager()->getDatabases()->getMaster()->getDatabaseName();
         CM_Db_Db::exec('DROP DATABASE IF EXISTS `' . $db . '_test`');
     }
     return $versionBumps;
 }
Example #11
0
File: TH.php Project: aladin1394/CM
 public static function clearCache()
 {
     CM_Cache_Shared::getInstance()->flush();
     CM_Cache_Local::getInstance()->flush();
 }
Example #12
0
 protected static function _createStatic(array $data)
 {
     $key = (string) $data['key'];
     $serverId = $data['serverId'];
     $adapterType = (int) $data['adapterType'];
     $mediaId = !empty($data['mediaId']) ? (string) $data['mediaId'] : null;
     $id = CM_Db_Db::insert('cm_streamChannel', ['key' => $key, 'createStamp' => time(), 'type' => static::getTypeStatic(), 'adapterType' => $adapterType], null, ['id' => ['literal' => 'LAST_INSERT_ID(id)']]);
     CM_Db_Db::insert('cm_streamChannel_media', ['id' => $id, 'serverId' => $serverId, 'mediaId' => $mediaId], null, ['id' => ['literal' => 'LAST_INSERT_ID(id)']]);
     $cacheKey = CM_CacheConst::StreamChannel_Id . '_key' . $key . '_adapterType:' . $adapterType;
     CM_Cache_Shared::getInstance()->delete($cacheKey);
     return new static($id);
 }
Example #13
0
 public function delete($type, array $id)
 {
     CM_Cache_Shared::getInstance()->delete($this->_getCacheKey($type, $id));
 }
Example #14
0
 protected static function _createStatic(array $data)
 {
     $key = (string) $data['key'];
     $adapterType = (int) $data['adapterType'];
     $id = CM_Db_Db::insert('cm_streamChannel', array('key' => $key, 'type' => static::getTypeStatic(), 'adapterType' => $adapterType));
     $cacheKey = CM_CacheConst::StreamChannel_Id . '_key' . $key . '_adapterType:' . $adapterType;
     CM_Cache_Shared::getInstance()->delete($cacheKey);
     return new static($id);
 }
Example #15
0
 private function _clearCache()
 {
     $cacheKey = CM_CacheConst::Option;
     CM_Cache_Shared::getInstance()->delete($cacheKey);
 }