本文整理汇总了PHP中Nette\Caching\Cache::remove方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::remove方法的具体用法?PHP Cache::remove怎么用?PHP Cache::remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Caching\Cache
的用法示例。
在下文中一共展示了Cache::remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFileLastCommit
/**
* Returns file last commit infos
*
* @param string $fileName
* @param bool $useCache
* @return mixed
* @throws gitHubException
*/
public function getFileLastCommit($fileName, $useCache = TRUE)
{
if (!$useCache) {
$this->cache->remove($fileName);
}
return $this->cache->load($fileName, function () use($fileName) {
$path = $this->subdir ? $this->subdir . '/' : '';
$url = self::GITHUB_URL . '/' . $this->user . '/' . $this->repo . '/commits?path=' . $path . $fileName;
$tree = $this->run($url);
return count($tree) === 0 ? NULL : $tree[0];
});
}
示例2: remove
/**
* @param User $user
* @throws ForeignKeyConstraintViolationException
*/
public function remove(User $user)
{
try {
$this->cache->remove($user);
// will be recreated if an error occur
$userID = $user->getId();
$this->em->remove($user);
$this->em->flush();
$this->onSuccessUserRemoval($user, $userID);
} catch (ForeignKeyConstraintViolationException $e) {
// todo log
throw $e;
}
}
示例3: update
/**
* @param array $values
* @param User|null $user
* @return ValidationObject
*/
public function update(array $values, User $user)
{
$this->em->beginTransaction();
$user->setFirstName($values['first_name']);
$user->setLastName($values['last_name']);
$validationObject = new ValidationObject();
// todo could be optimized
$user->clearRoles();
$role = $this->getRole($values['role'], $validationObject);
if (!$validationObject->isValid()) {
$this->em->rollback();
return $validationObject;
}
$user->addRole($role);
$this->em->persist($user);
$this->em->flush();
if ($validationObject->isValid()) {
$this->em->commit();
$this->onSuccessUserEditing($user);
$this->cache->remove($user->getCacheKey());
} else {
$this->em->rollback();
}
return $validationObject;
}
示例4: processMessage
/**
* Process all messages.
*/
private function processMessage()
{
if ($this->processed) {
return;
}
$this->processed = TRUE;
$files = glob($this->fileMailer->getTempDirectory() . DIRECTORY_SEPARATOR . '*.' . FileMailer::FILE_EXTENSION);
foreach ($files as $path) {
$cacheKey = basename($path);
if ($this->removeExpired($path)) {
$this->cache->remove($cacheKey);
continue;
}
$message = $this->cache->load($cacheKey);
if ($message === NULL) {
$message = FileMailer::mailParser(file_get_contents($path), $cacheKey);
$this->cache->save($cacheKey, $message);
}
$time = new DateTime();
if ($message->date > $time->modify($this->newMessageTime)) {
$this->countNew++;
} else {
$message->isOld = TRUE;
}
$this->countAll++;
$this->messages[] = $message;
}
usort($this->messages, function ($a1, $a2) {
return $a2->date->getTimestamp() - $a1->date->getTimestamp();
});
}
示例5: cleanParametersCache
/**
* @return void
*/
public function cleanParametersCache()
{
$this->parameters = NULL;
if ($this->cache) {
$this->cache->remove(self::PARAMETER_KEY);
}
}
示例6: save
public function save(array $values)
{
$options = $this->prepareOptions($this->findOptions());
foreach ((array) $values as $key => $value) {
$options[$key]->setValue($value == '' ? null : $value);
$this->em->persist($options[$key]);
}
try {
$this->em->flush();
$this->cache->remove(Option::getCacheKey());
$this->onSuccessOptionsSaving();
} catch (\Exception $e) {
$this->em->rollback();
$this->em->close();
$this->logger->addError(sprintf('Save Options error: %s | error message: %s', date('Y-m-d H:i:s'), $e->getMessage()));
throw $e;
}
}
示例7: getDomains
private function getDomains() : array
{
$this->repository->onAfterInsert[] = function () {
$this->cache->remove(NULL);
};
return $this->cache->load(NULL, function (&$dependencies) {
$dependencies[Nette\Caching\Cache::TAGS] = [];
return array_map(function (Ytnuk\Web\Domain\Entity $entity) use($dependencies) {
$dependencies[Nette\Caching\Cache::TAGS] = array_merge($dependencies[Nette\Caching\Cache::TAGS], $entity->getCacheTags());
return $entity->id;
}, iterator_to_array($this->repository->findAll()));
});
}
示例8: invalidateByQuery
/**
* Invalidates according graph Uri entries, the result and all triple pattern.
*
* @param Query $queryObject All data according to this query will be invalidated.
*/
public function invalidateByQuery(Query $queryObject)
{
// log it
$this->addToLog(array('method' => 'invalidateByQuery', 'parameter' => array('queryObject' => $queryObject)));
$query = $queryObject->getQuery();
// load query cache container by given query
$queryCacheContainer = $this->cache->load($query);
/**
* remove according query from the query list which belongs to one of the graph URI's in the query
* cache container.
*/
if (true === is_array($queryCacheContainer['graph_uris'])) {
foreach ($queryCacheContainer['graph_uris'] as $graphUri) {
$queryList = $this->cache->load($graphUri);
unset($queryList[$query]);
// if graphUri entry is empty after the operation, remove it from the cache
if (0 == count($queryList)) {
$this->cache->remove($graphUri);
// otherwise save updated entry
} else {
$this->cache->save($graphUri, $queryList);
}
}
}
// check for according triple pattern
if (true === is_array($queryCacheContainer['triple_pattern'])) {
foreach ($queryCacheContainer['triple_pattern'] as $patternKey) {
$queryList = $this->cache->load($patternKey);
unset($queryList[$query]);
// if patternKey entry is empty after the operation, remove it from the cache
if (0 == count($queryList)) {
$this->cache->remove($patternKey);
// otherwise save updated entry
} else {
$this->cache->save($patternKey, $queryList);
}
}
}
/**
* Remove query cache container
*/
$this->cache->remove($query);
}
示例9: saveLog
/**
* @param string $message
* @param string $event
* @param int|null $userID
* @throws \Exception
*/
public function saveLog($message, $event, $userID = null)
{
$eventLog = $this->getEventLog($event);
if ($eventLog === null) {
return;
// todo monolog log
}
if (!$this->isEventLoggable($eventLog)) {
return;
}
try {
$user = null;
if (isset($userID)) {
$user = $this->em->getReference(User::class, $userID);
}
$newLog = new Log($message, $this->em->getReference(EventLog::class, $eventLog->getId()), $this->request->getRemoteAddress(), $user);
$this->em->persist($newLog)->flush();
} catch (ForeignKeyConstraintViolationException $e) {
// todo if user doesn't exist
$this->cache->remove(self::getEventLogCacheKey($event));
}
}
示例10: save
/**
* @param Role $role
* @param array $permissionDefinitions
* @throws DBALException
* @throws \Exception
*/
public function save(Role $role, array $permissionDefinitions)
{
$resources = $this->em->createQuery('SELECT r FROM ' . Resource::class . ' r INDEX BY r.id')->execute();
$privileges = $this->em->createQuery('SELECT p FROM ' . Privilege::class . ' p INDEX BY p.id')->execute();
try {
$this->em->beginTransaction();
$this->em->createQuery('DELETE ' . Permission::class . ' p
WHERE p.role = :role')->execute(['role' => $role->getId()]);
$parentRole = null;
if ($role->hasParent()) {
/** @var Role $parentRole */
$parentRole = $this->em->find(Role::class, $role->getParentId());
}
foreach ($permissionDefinitions as $definition => $isAllowed) {
$isAllowed = (bool) $isAllowed;
$x = explode('-', $definition);
// eg. 1-3
/** @var \Users\Authorization\Resource $resource */
$resource = $resources[$x[0]];
/** @var Privilege $privilege */
$privilege = $privileges[$x[1]];
// check Users\Authorization\Authorizator ACL assembling
// Role without parent
// privilege: allowed -> must be in database
// privilege: denied -> does NOT have to be in database
// Role with parent (all depths)
/*
------------------------------------------------------------
parent | descendant | should be persisted?
------------------------------------------------------------
allowed allowed NO
allowed denied YES
denied denied NO
denied allowed YES
------------------------------------------------------------
We save records where permission and denial differ
*/
if ($parentRole !== null) {
// has parent
if ($this->authorizator->isAllowed($parentRole, $resource->getName(), $privilege->getName()) === $isAllowed) {
continue;
}
} else {
// doesn't have parent
if ($isAllowed === false) {
continue;
}
}
$permission = new Permission($role, $resource, $privilege, $isAllowed);
$this->em->persist($permission);
}
$this->em->flush();
$this->em->commit();
$this->cache->remove('acl');
$this->onSuccessRolePermissionsEditing($role);
} catch (\Exception $e) {
$this->em->rollback();
$this->em->close();
// todo log error
throw new $e();
}
}
示例11: clearImageVersion
/**
* @param string $namespace
* @param string $name
*/
public function clearImageVersion($namespace, $name)
{
$this->cache->remove('version/' . $namespace . '/' . $name);
}
示例12: clearStringsCache
/**
* Clears strings cache
* @return HQ\DbTranslator
*/
public function clearStringsCache()
{
$cacheName = $this->getStringsCacheName();
$this->cache->remove($cacheName);
return $this;
}
示例13: deleteSection
/**
* @param int $section
*/
public function deleteSection($section)
{
$this->cache->remove($section);
}
示例14: cleanTargetCache
private function cleanTargetCache(Brabijan\SeoComponents\Router\Target $target)
{
$this->cache->remove(serialize($target));
}
示例15: getValue
/**
* Vrátí nacachované hodnoty z controlleru.
* @return mixed|NULL
*/
public function getValue()
{
$files = $this->cache->load($this->getTokenizedCacheName($this->token));
$this->cache->remove($this->getTokenizedCacheName($this->token));
return $files;
}