public static function setAsProcessed($tableName, $identifier) { $processedTables = static::resolveProcessedTableNames($identifier); if (!in_array($tableName, $processedTables)) { $processedTables[] = $tableName; GeneralCache::cacheEntry($identifier, $processedTables); } }
public static function cacheEntry($identifier, $entry) { assert('is_string($entry) || is_numeric($entry)'); parent::cacheEntry($identifier, $entry); if (static::supportsAndAllowsDatabaseCaching()) { ZurmoRedBean::exec("insert into actual_rights_cache\n (identifier, entry) values ('" . $identifier . "', '" . $entry . "') on duplicate key\n update entry = " . $entry); } }
/** * Any changes to the model must be re-cached. * @see RedBeanModel::save() */ public function save($runValidation = true, array $attributeNames = null) { $saved = parent::save($runValidation, $attributeNames); if ($saved) { GeneralCache::cacheEntry('CustomFieldData' . $this->name, $this); } return $saved; }
/** * Any changes to the model must be re-cached. * @see RedBeanModel::save() */ public function save($runValidation = true, array $attributeNames = null) { $saved = parent::save($runValidation, $attributeNames); if ($saved) { GeneralCache::cacheEntry('NamedSecurableItem' . $this->name, $this); } return $saved; }
public function testCanSetNullValueToCache() { //if memcache is off this test will fail because memcache will not cache null values. if (MEMCACHE_ON) { GeneralCache::cacheEntry('somethingForTesting', null); $value = GeneralCache::getEntry('somethingForTesting'); $this->assertNull($value); } }
/** * Get all read subscription model class names * @return array|mixed */ public static function getReadSubscriptionModelClassNames() { try { return GeneralCache::getEntry('readPermissionsSubscriptionModelClassNames'); } catch (NotFoundException $e) { $readPermissionsSubscriptionModelClassNames = self::findReadSubscriptionModelClassNames(); GeneralCache::cacheEntry('readPermissionsSubscriptionModelClassNames', $readPermissionsSubscriptionModelClassNames); return $readPermissionsSubscriptionModelClassNames; } }
/** * @param $user * @return array|mixed */ public static function resolveByCacheAndGetVisibleAndOrderedAdminTabMenuByUser($user) { assert('$user instanceof User && $user != null'); try { $items = GeneralCache::getEntry(self::getAdminMenuViewItemsCacheIdentifier()); } catch (NotFoundException $e) { $items = self::getVisibleAndOrderedAdminTabMenuByUser($user); GeneralCache::cacheEntry(self::getAdminMenuViewItemsCacheIdentifier(), $items); } return $items; }
/** * Given a user, return an array of module names and their translated labels, for which the user * has the right to access and only modules that support the global search. * @param User $user * @return array of module names and labels. */ public static function getGlobalSearchScopingModuleNamesAndLabelsDataByUser(User $user) { assert('$user->id > 0'); try { return GeneralCache::getEntry(self::getGlobalSearchScopingCacheIdentifier($user)); } catch (NotFoundException $e) { $moduleNamesAndLabels = self::findGlobalSearchScopingModuleNamesAndLabelsDataByUser($user); GeneralCache::cacheEntry(self::getGlobalSearchScopingCacheIdentifier($user), $moduleNamesAndLabels); return $moduleNamesAndLabels; } }
/** * Override of the parent method because of problems with Yii's default cache * @see CDbMessageSource::loadMessages() * @param string $category * @param string $languageCode * @return array $messages */ protected function loadMessages($category, $languageCode) { assert('is_string($category)'); assert('is_string($languageCode)'); try { $messages = GeneralCache::getEntry(self::getMessageSourceCacheIdentifier($category, $languageCode)); } catch (NotFoundException $e) { $messages = $this->loadMessagesFromDb($category, $languageCode); GeneralCache::cacheEntry(self::getMessageSourceCacheIdentifier($category, $languageCode), $messages); } return $messages; }
/** * @param $user * @return array|mixed */ public static function resolveByCacheAndGetVisibleAndOrderedAdminTabMenuByUser($user) { assert('$user instanceof User && $user != null'); try { // not using default value to save cpu cycles on requests that follow the first exception. $items = GeneralCache::getEntry(self::getAdminMenuViewItemsCacheIdentifier()); } catch (NotFoundException $e) { $items = self::getVisibleAndOrderedAdminTabMenuByUser($user); GeneralCache::cacheEntry(self::getAdminMenuViewItemsCacheIdentifier(), $items); } return $items; }
/** * Given a user, return an array of module names and their translated labels, for which the user * has the right to access and only modules that support the global search. * @param User $user * @return array of module names and labels. */ public static function getGlobalSearchScopingModuleNamesAndLabelsDataByUser(User $user) { assert('$user->id > 0'); try { // not using default value to save cpu cycles on requests that follow the first exception. return GeneralCache::getEntry(self::getGlobalSearchScopingCacheIdentifier($user)); } catch (NotFoundException $e) { $moduleNamesAndLabels = self::findGlobalSearchScopingModuleNamesAndLabelsDataByUser($user); GeneralCache::cacheEntry(self::getGlobalSearchScopingCacheIdentifier($user), $moduleNamesAndLabels); return $moduleNamesAndLabels; } }
/** * Override of the parent method because of problems with Yii's default cache * @see CDbMessageSource::loadMessages() * @param string $category * @param string $languageCode * @return array $messages */ protected function loadMessages($category, $languageCode) { assert('is_string($category)'); assert('is_string($languageCode)'); try { // not using default value to save cpu cycles on requests that follow the first exception. $messages = GeneralCache::getEntry(self::getMessageSourceCacheIdentifier($category, $languageCode)); } catch (NotFoundException $e) { $messages = $this->loadMessagesFromDb($category, $languageCode); GeneralCache::cacheEntry(self::getMessageSourceCacheIdentifier($category, $languageCode), $messages); } return $messages; }
/** * Import all files that need to be included(for lazy loading) * @param $event */ public function handleImports($event) { try { $filesToInclude = GeneralCache::getEntry('filesToIncludeForTests'); } catch (NotFoundException $e) { $filesToInclude = FileUtil::getFilesFromDir(Yii::app()->basePath . '/modules', Yii::app()->basePath . '/modules', 'application.modules', true); $filesToIncludeFromFramework = FileUtil::getFilesFromDir(Yii::app()->basePath . '/core', Yii::app()->basePath . '/core', 'application.core', true); $totalFilesToIncludeFromModules = count($filesToInclude); foreach ($filesToIncludeFromFramework as $key => $file) { $filesToInclude[$totalFilesToIncludeFromModules + $key] = $file; } GeneralCache::cacheEntry('filesToIncludeForTests', $filesToInclude); } foreach ($filesToInclude as $file) { Yii::import($file); } }
public static function getMungableModelClassNames() { try { return GeneralCache::getEntry('mungableModelClassNames'); } catch (NotFoundException $e) { $mungableClassNames = self::findMungableModelClassNames(); GeneralCache::cacheEntry('mungableModelClassNames', $mungableClassNames); return $mungableClassNames; } }
/** * Returns metadata for the module. * @see getDefaultMetadata() * @param $user The current user. * @returns An array of metadata. */ public static function getMetadata(User $user = null) { $className = get_called_class(); if ($user == null) { try { // not using default value to save cpu cycles on requests that follow the first exception. return GeneralCache::getEntry($className . 'Metadata'); } catch (NotFoundException $e) { } } $metadata = MetadataUtil::getMetadata($className, $user); if (YII_DEBUG) { $className::assertMetadataIsValid($metadata); } if ($user == null) { GeneralCache::cacheEntry($className . 'Metadata', $metadata); } return $metadata; }
/** * @param array $metadata */ public static function setMetadata(array $metadata) { $className = get_called_class(); if (YII_DEBUG) { $className::assertMetadataIsValid($metadata); } MetadataUtil::setMetadata($className, $metadata); GeneralCache::cacheEntry($className . 'Metadata', $metadata); }
public function testForgetAllNotDeleteOtherDataFromCache() { if (MEMCACHE_ON && !PHP_CACHING_ON) { GeneralCache::cacheEntry('somethingForTesting4', 34); $value = GeneralCache::getEntry('somethingForTesting4'); $this->assertEquals(34, $value); $originalAdditionalStringForCachePrefix = GeneralCache::getAdditionalStringForCachePrefix(); GeneralCache::setAdditionalStringForCachePrefix('ATEST'); GeneralCache::cacheEntry('somethingForTesting4', 43); $value = GeneralCache::getEntry('somethingForTesting4'); $this->assertEquals(43, $value); GeneralCache::forgetAll(); try { GeneralCache::getEntry('somethingForTesting4'); $this->fail('NotFoundException exception is not thrown.'); } catch (NotFoundException $e) { $this->assertTrue(true); } GeneralCache::setAdditionalStringForCachePrefix($originalAdditionalStringForCachePrefix); $value = GeneralCache::getEntry('somethingForTesting4'); $this->assertEquals(34, $value); } }
protected static function registerUniqueIndexByMemberName($member, $modelClassName) { $indexName = RedBeanModelMemberIndexMetadataAdapter::resolveRandomIndexName($member, true); $uniqueIndexes = GeneralCache::getEntry(static::CACHE_KEY, array()); $uniqueIndexes[$modelClassName][$indexName] = array('members' => array($member), 'unique' => true); GeneralCache::cacheEntry(static::CACHE_KEY, $uniqueIndexes); }
/** * @param string $cacheType * @param mixed $value */ protected static function setCacheIncrementValue($cacheType, $value) { GeneralCache::cacheEntry(static::$cacheIncrementValueVariableName . $cacheType, $value); }
public function testForgetAll() { $a = new A(); $a->a = 1; $a->uniqueRequiredEmail = '*****@*****.**'; $this->assertTrue($a->save()); $modelIdentifier = $a->getModelIdentifier(); $modelFromCache = RedBeanModelsCache::getModel($modelIdentifier); $this->assertEquals(1, $modelFromCache->a); $this->assertEquals('*****@*****.**', $modelFromCache->uniqueRequiredEmail); // Set some GeneralCache, which should stay in cache after cleanup GeneralCache::cacheEntry('somethingForTesting', 34); $value = GeneralCache::getEntry('somethingForTesting'); $this->assertEquals(34, $value); RedBeanModelsCache::forgetAll(); try { RedBeanModelsCache::getModel($modelIdentifier); $this->fail('NotFoundException exception is not thrown.'); } catch (NotFoundException $e) { // Data from generalCache should still be in cache $value = GeneralCache::getEntry('somethingForTesting'); $this->assertEquals(34, $value); } }
protected static function cacheValue($moduleName, $configKey, $value, $userId = null) { if (!static::ENABLE_CACHE) { return; } $cacheKey = static::getCacheKey($moduleName, $configKey, $userId); GeneralCache::cacheEntry($cacheKey, $value); }
protected function renderCacheInfo() { if (defined('SHOW_CACHE_DUMP') && SHOW_CACHE_DUMP) { $test = GeneralCache::getEntry('iamatestidentifier', 0); GeneralCache::cacheEntry('iamatestidentifier', $test + 1); $cacheJson = GeneralCache::dumpPhpCachedItemsAsJson(); $cacheJson = str_replace("{", "{<br/>", $cacheJson); $cacheJson = str_replace("}", "}<br/>", $cacheJson); $cacheJson = str_replace(",", ",<br/>", $cacheJson); return "<strong>PHP-Cache content:</strong><br/>" . $cacheJson . "<br />"; } else { return ""; } }
public static function getNonMonitorJobClassNames() { try { $jobClassNames = GeneralCache::getEntry(self::NON_MONITOR_JOBS_CACHE_ID); } catch (NotFoundException $e) { $jobClassNames = array(); $modules = Module::getModuleObjects(); foreach ($modules as $module) { $jobsClassNames = $module::getAllClassNamesByPathFolder('jobs'); foreach ($jobsClassNames as $jobClassName) { $classToEvaluate = new ReflectionClass($jobClassName); if (is_subclass_of($jobClassName, 'BaseJob') && !$classToEvaluate->isAbstract() && $jobClassName != 'MonitorJob') { $jobClassNames[] = $jobClassName; } } } GeneralCache::cacheEntry(self::NON_MONITOR_JOBS_CACHE_ID, $jobClassNames); } return $jobClassNames; }
/** * Returns metadata for the model. Attempts to cache metadata, if it is not already cached. * @see getDefaultMetadata() * @returns An array of metadata. */ public static function getMetadata() { try { return GeneralCache::getEntry(get_called_class() . 'Metadata'); } catch (NotFoundException $e) { $className = get_called_Class(); $defaultMetadata = $className::getDefaultMetadata(); $metadata = array(); foreach (array_reverse(RuntimeUtil::getClassHierarchy($className, static::$lastClassInBeanHeirarchy)) as $modelClassName) { if ($modelClassName::getCanHaveBean()) { if ($modelClassName::canSaveMetadata()) { try { $globalMetadata = GlobalMetadata::getByClassName($modelClassName); $metadata[$modelClassName] = unserialize($globalMetadata->serializedMetadata); } catch (NotFoundException $e) { if (isset($defaultMetadata[$modelClassName])) { $metadata[$modelClassName] = $defaultMetadata[$modelClassName]; } } } else { if (isset($defaultMetadata[$modelClassName])) { $metadata[$modelClassName] = $defaultMetadata[$modelClassName]; } } } } if (YII_DEBUG) { self::assertMetadataIsValid($metadata); } GeneralCache::cacheEntry(get_called_class() . 'Metadata', $metadata); return $metadata; } }
/** * Downloads the l10n info XML file * * @return SimpleXMLElement */ protected static function getServerInfo() { if (self::$l10nInfo && isset(self::$l10nInfo) && self::$l10nInfo->version == '1.1') { return self::$l10nInfo; } $cacheIdentifier = 'l10nServerInfo'; try { self::$l10nInfo = GeneralCache::getEntry($cacheIdentifier); } catch (NotFoundException $e) { $infoFileUrl = self::$serverDomain . '/' . self::$infoXmlPath; $xml = simplexml_load_file($infoFileUrl); self::$l10nInfo = json_decode(json_encode($xml)); GeneralCache::cacheEntry($cacheIdentifier, self::$l10nInfo); } if (isset(self::$l10nInfo->version) && self::$l10nInfo->version == '1.1') { return self::$l10nInfo; } throw new FailedServiceException(); }
public static function cacheEntry($identifier, $entry) { GeneralCache::cacheEntry($identifier, $entry); }
public function testCacheBoolean() { GeneralCache::cacheEntry('ABoolean', true); $boolean = GeneralCache::getEntry('ABoolean'); $this->assertTrue($boolean); }
protected static function setColumnsForPolymorphicLink($relatedModelClassName, $linkName) { $columns = array(); $columns[] = RedBeanModelMemberToColumnUtil::resolveForeignKeyColumnMetadata(RedBeanModelMemberToColumnUtil::resolve($linkName) . '_id'); $columns[] = static::resolvePolymorphicTypeColumnByLinkName($linkName); $tableName = $relatedModelClassName::getTableName(); $polymorphicLinkColumns = GeneralCache::getEntry(static::CACHE_KEY, array()); $polymorphicLinkColumns[$tableName] = $columns; GeneralCache::cacheEntry(static::CACHE_KEY, $polymorphicLinkColumns); }
protected static function getAllEmailTemplateElementClassNamesWithFilterFromCache($identifier, $filter) { try { $filteredElementClassNames = GeneralCache::getEntry($identifier); } catch (NotFoundException $e) { $filteredElementClassNames = static::getAllEmailTemplateElementClassNames($filter); GeneralCache::cacheEntry($identifier, $filteredElementClassNames); } return $filteredElementClassNames; }
public function testForgetAll() { if (MEMCACHE_ON && Yii::app()->cache !== null) { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $account = new Account(); $account->name = 'Ocean Inc2.'; $this->assertTrue($account->save()); $combinedPermissions = 5; // Set some GeneralCache, which should stay in cache after cleanup GeneralCache::cacheEntry('somethingForTesting', 34); $value = GeneralCache::getEntry('somethingForTesting'); $this->assertEquals(34, $value); PermissionsCache::cacheCombinedPermissions($account, $super, $combinedPermissions); $combinedPermissionsFromCache = PermissionsCache::getCombinedPermissions($account, $super); $this->assertEquals($combinedPermissions, $combinedPermissionsFromCache); PermissionsCache::forgetAll(); try { PermissionsCache::getCombinedPermissions($account, $super); $this->fail('NotFoundException exception is not thrown.'); } catch (NotFoundException $e) { // Data from generalCache should still be in cache $value = GeneralCache::getEntry('somethingForTesting'); $this->assertEquals(34, $value); } } // To-Do: Add test for forgetAll with $forgetDbLevelCache = true. It could be added to testForgetAll() function. // To-Do: Add test for forgetSecurableItem with $forgetDbLevelCache = true. . It could be added to testForgetSecurableItem() function. }