invalidateCache() public method

This is the distributed cache controller. Use it if you want to invalidate caches on a distributed backend (setDistributedCache() and getDistributedCache()). You don't have to define the full key, instead you can pass only the starting part of the key. This means, if you have following caches defined: - news/list/2 - news/list/3 - news/list/4 - news/comments/134 - news/comments/51 you can mark all listing caches as invalid by calling - invalidateCache('news/list'); or mark all caches as invalid which starts with news/ you can call: - invalidateCache('news'); The invalidation mechanism explodes the key by / and checks all levels whether they're marked as invalid (through a microsecond timestamp) or not. Default is $time is mark all caches as invalid which are older than CURRENT. This method is called by the Jarves\Configuration\Event::$clearCaches configuration
public invalidateCache ( string $key, integer $time = null ) : boolean
$key string
$time integer Unix timestamp. Default is microtime(true). Uses float for ms.
return boolean
Beispiel #1
0
 /**
  * @ApiDoc(
  *  section="ACL Management",
  *  description="Saves the given rules"
  * )
  *
  * @Rest\RequestParam(name="targetId", requirements=".+", strict=true, description="Target id")
  * @Rest\RequestParam(name="targetType", requirements=".+", strict=true, description="Target type")
  * @Rest\RequestParam(name="rules", strict=false, description="ACL rules array")
  *
  * @Rest\Post("/user/acl")
  *
  * @param  int $targetId
  * @param  int $targetType
  * @param  array $rules
  *
  * @return bool
  */
 public function saveAcl($targetId, $targetType, $rules = null)
 {
     $targetId += 0;
     $targetType += 0;
     AclQuery::create()->filterByTargetId($targetId)->filterByTargetType($targetType)->delete();
     if (0 < count($rules)) {
         $i = 1;
         if (is_array($rules)) {
             foreach ($rules as $rule) {
                 $ruleObject = new Acl();
                 $ruleObject->setPrio($i);
                 $ruleObject->setTargetType($targetType);
                 $ruleObject->setTargetId($targetId);
                 $ruleObject->setTargetId($targetId);
                 $ruleObject->setObject(Objects::normalizeObjectKey(@$rule['object']));
                 $ruleObject->setSub(filter_var(@$rule['sub'], FILTER_VALIDATE_BOOLEAN));
                 $ruleObject->setAccess(filter_var(@$rule['access'], FILTER_VALIDATE_BOOLEAN));
                 $ruleObject->setFields(@$rule['fields']);
                 $ruleObject->setConstraintType(@$rule['constraintType']);
                 $ruleObject->setConstraintCode(@$rule['constraintCode']);
                 $ruleObject->setMode(@$rule['mode'] + 0);
                 $ruleObject->save();
                 $i++;
             }
         }
     }
     $this->cacher->invalidateCache('core/acl');
     return true;
 }
 /**
  * @param Event $eventConfig
  * @param GenericEvent $event
  */
 public function call(Event $eventConfig, $event)
 {
     if ($eventConfig->getCalls()) {
         foreach ($eventConfig->getCalls() as $call) {
             call_user_func_array($call, [$event]);
         }
     }
     if ($eventConfig->getClearCaches()) {
         foreach ($eventConfig->getClearCaches() as $cacheKey) {
             $this->cacher->invalidateCache($cacheKey);
         }
     }
     if ($eventConfig->getServiceCalls()) {
         foreach ($eventConfig->getServiceCalls() as $serviceCall) {
             list($service, $method) = explode('::', $serviceCall);
             if ($this->container->has($service)) {
                 $service = $this->container->get($service);
                 $service->{$method}($event);
             }
         }
     }
 }
Beispiel #3
0
    /**
     * @param string $bundle
     * @param string $lang
     * @param array  $translation
     *
     * @return bool
     * @throws FileNotWritableException
     */
    public function saveLanguage($bundle, $lang, $translation)
    {
        $file = $this->getJarves()->resolvePath("@{$bundle}/{$lang}.po", 'Resources/translations');
        @mkdir(dirname($file), 777, true);
        if (!is_writable($file)) {
            throw new FileNotWritableException(sprintf('File `%s` is not writable.', $file));
        }
        $translations = json_decode($translation, true);
        $current = $this->parsePo($file);
        $fh = fopen($file, 'w');
        if ($fh == false) {
            return false;
        }
        $pluralForms = $this->getPluralForm($lang) ?: 'nplurals=2; plural=(n!=1);';
        if ($current) {
            $current['container']['Plural-Forms'] = $pluralForms;
            $current['container']['PO-Revision-Date'] = date('Y-m-d H:iO');
            fwrite($fh, 'msgid ""' . "\n" . 'msgstr ""' . "\n");
            foreach ($current['container'] as $k => $v) {
                fwrite($fh, '"' . $k . ': ' . $v . '\\n"' . "\n");
            }
            fwrite($fh, "\n\n");
        } else {
            //write initial container
            fwrite($fh, '
               msgid ""
               msgstr ""
               "Project-Id-Version: Jarves cms - ' . $bundle . '\\n"
"PO-Revision-Date: ' . date('Y-m-d H:iO') . '\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Language: ' . $lang . '\\n"
"Plural-Forms: ' . $pluralForms . '\\n"' . "\n\n");
        }
        if (count($translations) > 0) {
            foreach ($translations as $key => $translation) {
                if (strpos($key, "") !== false) {
                    //we have a context
                    $context = self::toPoString(substr($key, 0, strpos($key, "")));
                    $id = self::toPoString(substr($key, strpos($key, "") + 1));
                    fwrite($fh, 'msgctxt ' . $context . "\n");
                    fwrite($fh, 'msgid ' . $id . "\n");
                } else {
                    fwrite($fh, 'msgid ' . self::toPoString($key) . "\n");
                }
                if (is_array($translation)) {
                    fwrite($fh, 'msgid_plural ' . self::toPoString($translation['plural']) . "\n");
                    unset($translation['plural']);
                    foreach ($translation as $k => $v) {
                        fwrite($fh, 'msgstr[' . $k . '] ' . self::toPoString($v) . "\n");
                    }
                } else {
                    fwrite($fh, 'msgstr ' . self::toPoString($translation) . "\n");
                }
                fwrite($fh, "\n");
            }
        }
        fclose($fh);
        $this->cacher->invalidateCache('core/lang');
        return true;
    }