/** * Given a name, get the custom field data model. Attempts to retrieve from cache, if it is not available, * will attempt to retrieve from persistent storage, cache the model, and return. * @param string $name * @return CustomFieldData model * @throws NotFoundException */ public static function getByName($name, $shouldCache = true) { if (isset(self::$cachedModelsByName[$name])) { return self::$cachedModelsByName[$name]; } try { // not using default value to save cpu cycles on requests that follow the first exception. return GeneralCache::getEntry('CustomFieldData' . $name); } catch (NotFoundException $e) { assert('is_string($name)'); assert('$name != ""'); $bean = ZurmoRedBean::findOne('customfielddata', "name = :name ", array(':name' => $name)); assert('$bean === false || $bean instanceof RedBean_OODBBean'); if ($bean === false) { $customFieldData = new CustomFieldData(); $customFieldData->name = $name; $customFieldData->serializedData = serialize(array()); // An unused custom field data does not present as needing saving. $customFieldData->setNotModified(); } else { $customFieldData = self::makeModel($bean); } if ($shouldCache) { self::$cachedModelsByName[$name] = $customFieldData; GeneralCache::cacheEntry('CustomFieldData' . $name, $customFieldData); } return $customFieldData; } }
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 curent increment value, based on $cacheType. Cache types can be: * "G:" - for GlobalCache * "M:" - for RedBeanModelsCache * "P:" - for PermissionCache * We need to distinct those cache types, because we should be able to forget only GlobalCache(increment * cache increment value), while other two cache types will contain valid data. * @param string $cacheType * @return int|mixed */ protected static function getCacheIncrementValue($cacheType) { try { $cacheIncrementValue = GeneralCache::getEntry(static::$cacheIncrementValueVariableName . $cacheType); } catch (NotFoundException $e) { $cacheIncrementValue = 0; static::setCacheIncrementValue($cacheType, $cacheIncrementValue); } return $cacheIncrementValue; }
/** * 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; } }
/** * 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; } }
/** * @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; }
/** * @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 { $messages = GeneralCache::getEntry(self::getMessageSourceCacheIdentifier($category, $languageCode)); } catch (NotFoundException $e) { $messages = $this->loadMessagesFromDb($category, $languageCode); GeneralCache::cacheEntry(self::getMessageSourceCacheIdentifier($category, $languageCode), $messages); } return $messages; }
/** * 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; }
/** * @return array */ public static function getMetadata() { $className = get_called_class(); try { return GeneralCache::getEntry($className . 'Metadata'); } catch (NotFoundException $e) { } $metadata = MetadataUtil::getMetadata($className); if (YII_DEBUG) { $className::assertMetadataIsValid($metadata); } GeneralCache::cacheEntry($className . 'Metadata', $metadata); return $metadata; }
/** * @return array */ public static function getMetadata() { $className = get_called_class(); 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); if (YII_DEBUG) { $className::assertMetadataIsValid($metadata); } GeneralCache::cacheEntry($className . 'Metadata', $metadata); return $metadata; }
/** * 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); } }
/** * Returns metadata for use in automatically generating the view. Will attempt to retrieve from cache if * available, otherwill retrieve from database and cache. * @see getDefaultMetadata() * @param $user The current user. * @returns An array of metadata. */ public static function getMetadata(User $user = null) { $className = static::resolveMetadataClassNameToUse(); if ($user == null) { try { 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; }
/** * Given a name, check the cache if the model is cached and return. Otherwise check the database for the record, * cache and return this model. * @param string $name */ public static function getByName($name) { assert('is_string($name)'); assert('$name != ""'); try { return GeneralCache::getEntry('NamedSecurableItem' . $name); } catch (NotFoundException $e) { $bean = R::findOne('namedsecurableitem', "name = :name ", array(':name' => $name)); assert('$bean === false || $bean instanceof RedBean_OODBBean'); if ($bean === false) { $model = new NamedSecurableItem(); $model->unrestrictedSet('name', $name); } else { $model = self::makeModel($bean); } } GeneralCache::cacheEntry('NamedSecurableItem' . $name, $model); return $model; }
/** * Returns metadata for use in automatically generating the view. Will attempt to retrieve from cache if * available, otherwill retrieve from database and cache. * @see getDefaultMetadata() * @param $user The current user. * @returns An array of metadata. */ public static function getMetadata(User $user = null) { $className = static::resolveMetadataClassNameToUse(); 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; }
/** * Given a name, check the cache if the model is cached and return. Otherwise check the database for the record, * cache and return this model. * @param string $name */ public static function getByName($name) { assert('is_string($name)'); assert('$name != ""'); try { // not using default value to save cpu cycles on requests that follow the first exception. return GeneralCache::getEntry('NamedSecurableItem' . $name); } catch (NotFoundException $e) { $bean = ZurmoRedBean::findOne('namedsecurableitem', "name = :name ", array(':name' => $name)); assert('$bean === false || $bean instanceof RedBean_OODBBean'); if ($bean === false) { $model = new NamedSecurableItem(); $model->unrestrictedSet('name', $name); } else { $model = self::makeModel($bean); } } GeneralCache::cacheEntry('NamedSecurableItem' . $name, $model); return $model; }
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; }
/** * Given a name, get the custom field data model. Attempts to retrieve from cache, if it is not available, * will attempt to retrieve from persistent storage, cache the model, and return. * @param string $name */ public static function getByName($name) { try { return GeneralCache::getEntry('CustomFieldData' . $name); } catch (NotFoundException $e) { assert('is_string($name)'); assert('$name != ""'); $bean = R::findOne('customfielddata', "name = '{$name}'"); assert('$bean === false || $bean instanceof RedBean_OODBBean'); if ($bean === false) { $customFieldData = new CustomFieldData(); $customFieldData->name = $name; $customFieldData->serializedData = serialize(array()); // An unused custom field data does not present as needing saving. $customFieldData->setNotModified(); return $customFieldData; } $model = self::makeModel($bean); GeneralCache::cacheEntry('CustomFieldData' . $name, $model); return $model; } }
public static function getEntry($identifier, $default = 'NOT_FOUND_EXCEPTION', $cacheDefaultValue = false) { try { return parent::getEntry($identifier, $default, $cacheDefaultValue); } catch (NotFoundException $e) { if (static::supportsAndAllowsDatabaseCaching()) { $row = ZurmoRedBean::getRow("select entry from actual_rights_cache " . "where identifier = '" . $identifier . "'"); if ($row != null && isset($row['entry'])) { //Calling parent because we don't need to re-cache the db cache item parent::cacheEntry($identifier, $row['entry']); return $row['entry']; } } if ($default === 'NOT_FOUND_EXCEPTION') { throw new NotFoundException(); } else { if ($cacheDefaultValue) { static::cacheEntry($identifier, $default); } return $default; } } }
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 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); } }
public static function resolveProcessedTableNames($identifier) { return GeneralCache::getEntry($identifier, array()); }
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); }
/** * 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 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); } }
/** * 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; } }
public static function getMungableModelClassNames() { try { return GeneralCache::getEntry('mungableModelClassNames'); } catch (NotFoundException $e) { $mungableClassNames = self::findMungableModelClassNames(); GeneralCache::cacheEntry('mungableModelClassNames', $mungableClassNames); return $mungableClassNames; } }
public static function getEntry($identifier) { return GeneralCache::getEntry($identifier); }
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); }