/**
  * @depends testCanSetValueToCache
  */
 public function testForgetEntry()
 {
     if (MEMCACHE_ON) {
         GeneralCache::cacheEntry('somethingForTesting3', 10);
         $value = GeneralCache::getEntry('somethingForTesting3');
         $this->assertEquals(10, $value);
         GeneralCache::forgetEntry('somethingForTesting3');
         try {
             GeneralCache::getEntry('somethingForTesting3');
             $this->fail('NotFoundException exception is not thrown.');
         } catch (NotFoundException $e) {
             $this->assertTrue(true);
         }
     }
 }
 protected function unrestrictedDelete()
 {
     unset(self::$cachedModelsByName[$this->name]);
     GeneralCache::forgetEntry('CustomFieldData' . $this->name);
     return parent::unrestrictedDelete();
 }
Exemple #3
0
 /**
  * Sets metadata for the model.
  * @see getDefaultMetadata()
  * @returns An array of metadata.
  */
 public static function setMetadata(array $metadata)
 {
     if (YII_DEBUG) {
         self::assertMetadataIsValid($metadata);
     }
     $className = get_called_class();
     foreach (array_reverse(RuntimeUtil::getClassHierarchy($className, static::$lastClassInBeanHeirarchy)) as $modelClassName) {
         if ($modelClassName::getCanHaveBean()) {
             if ($modelClassName::canSaveMetadata()) {
                 if (isset($metadata[$modelClassName])) {
                     try {
                         $globalMetadata = GlobalMetadata::getByClassName($modelClassName);
                     } catch (NotFoundException $e) {
                         $globalMetadata = new GlobalMetadata();
                         $globalMetadata->className = $modelClassName;
                     }
                     $globalMetadata->serializedMetadata = serialize($metadata[$modelClassName]);
                     $saved = $globalMetadata->save();
                     // TODO: decide how to deal with this properly if it fails.
                     //       ie: throw or return false, or something other than
                     //           this naughty assert.
                     assert('$saved');
                 }
             }
         }
     }
     self::forgetBeanModel(get_called_class());
     RedBeanModelsCache::forgetAllByModelType(get_called_class());
     GeneralCache::forgetEntry(get_called_class() . 'Metadata');
 }
 /**
  * @param $user
  */
 public static function forgetCacheEntryForTabMenuByUser($user)
 {
     $identifier = self::getMenuViewItemsCacheIdentifierByUser($user);
     GeneralCache::forgetEntry($identifier);
 }
 public static function clearCache($category, $languageCode)
 {
     assert('is_string($category)');
     assert('is_string($languageCode)');
     GeneralCache::forgetEntry(self::getMessageSourceCacheIdentifier($category, $languageCode));
 }
Exemple #6
0
 /**
  * Sets new metadata.
  * @param $metadata An array of metadata.
  * @param $user The current user.
  */
 public static function setMetadata(array $metadata, User $user = null)
 {
     $className = get_called_class();
     if (YII_DEBUG) {
         self::assertMetadataIsValid($metadata);
     }
     MetadataUtil::setMetadata($className, $metadata, $user);
     if ($user == null) {
         GeneralCache::forgetEntry($className . 'Metadata');
     }
 }
 /**
  * Import all files that need to be included(for lazy loading)
  * @param $event
  */
 public function handleImports($event)
 {
     //Clears file cache so that everything is clean.
     if (isset($_GET['clearCache']) && $_GET['clearCache'] == 1) {
         GeneralCache::forgetEntry('filesClassMap');
     }
     try {
         // not using default value to save cpu cycles on requests that follow the first exception.
         Yii::$classMap = GeneralCache::getEntry('filesClassMap');
     } catch (NotFoundException $e) {
         $filesToInclude = FileUtil::getFilesFromDir(Yii::app()->basePath . '/modules', Yii::app()->basePath . '/modules', 'application.modules');
         $filesToIncludeFromCore = FileUtil::getFilesFromDir(Yii::app()->basePath . '/core', Yii::app()->basePath . '/core', 'application.core');
         $totalFilesToIncludeFromModules = count($filesToInclude);
         foreach ($filesToIncludeFromCore as $key => $file) {
             $filesToInclude[$totalFilesToIncludeFromModules + $key] = $file;
         }
         foreach ($filesToInclude as $file) {
             Yii::import($file);
         }
         GeneralCache::cacheEntry('filesClassMap', Yii::$classMap);
     }
     Yii::app()->setAllClassesAreImported();
 }
Exemple #8
0
 public static function setMetadata(array $metadata)
 {
     if (YII_DEBUG) {
         self::assertMetadataIsValid($metadata);
     }
     // Save the mixed in Person metadata.
     if (isset($metadata['Person'])) {
         $modelClassName = 'Person';
         try {
             $globalMetadata = GlobalMetadata::getByClassName($modelClassName);
         } catch (NotFoundException $e) {
             $globalMetadata = new GlobalMetadata();
             $globalMetadata->className = $modelClassName;
         }
         $globalMetadata->serializedMetadata = serialize($metadata[$modelClassName]);
         $saved = $globalMetadata->save();
         assert('$saved');
     }
     if (isset($metadata['User'])) {
         parent::setMetadata($metadata);
     }
     GeneralCache::forgetEntry(get_called_class() . 'Metadata');
 }
 /**
  * Used by tests to reset value between tests.
  */
 public function flushModuleLabelTranslationParameters()
 {
     foreach (Yii::app()->params['supportedLanguages'] as $language => $notUsed) {
         GeneralCache::forgetEntry('moduleLabelTranslationParameters' . $language);
     }
 }