Пример #1
0
 /**
  * Load data from cache
  * @param        $cacheKey  Unique cache id
  * @param string $cachePrefix   Cache prefix
  * @return null Returns null if nothing found
  */
 public function load($cacheKey, $cachePrefix = '')
 {
     $cacheId = $this->_makeCacheId($cacheKey, $cachePrefix);
     if (!$this->_cache->test($cacheId)) {
         return null;
     }
     return $this->_cache->load($cacheId);
 }
Пример #2
0
 public function testTest()
 {
     $this->rediska->set('test', array('aaa', time(), null));
     $value = $this->cache->test('test');
     $this->assertTrue(is_integer($value));
     $value = $this->cache->test('test2');
     $this->assertFalse($value);
 }
Пример #3
0
 public function testTest()
 {
     $this->cache->save('aaa', 'test');
     $value = $this->cache->test('test');
     $this->assertTrue(is_integer($value));
     $value = $this->cache->test('test2');
     $this->assertFalse($value);
 }
Пример #4
0
 protected function _loadConfig($file)
 {
     if ($this->_useCache == false) {
         return parent::_loadConfig($file);
     }
     $configMTime = filemtime($file);
     $cacheId = "application_conf_" . md5($file . $this->getEnvironment());
     $cacheLastMTime = $this->_configCache->test($cacheId);
     //Valid cache?
     if ($cacheLastMTime !== false && $configMTime <= $cacheLastMTime) {
         return $this->_configCache->load($cacheId, true);
     }
     $config = parent::_loadConfig($file);
     $this->_configCache->save($config, $cacheId, array(), null);
     return $config;
 }
 /**
  * get by id
  * - results are cached
  *
  * @param string $_id the id of the peer
  * @return Voipmanager_Model_Snom_Location
  */
 public function get($_id)
 {
     $id = Tinebase_Record_Abstract::convertId($_id, $this->_modelName);
     if ($this->_cacheIdPrefix && $this->_cache) {
         $cacheId = $this->_cacheIdPrefix . $id;
         if ($this->_cache->test($id)) {
             $result = $this->_cache->load($id);
         } else {
             $result = $this->_backend->get($id);
             $this->_cache->save($result, $cacheId, array($this->_cacheIdPrefix), 5);
         }
     } else {
         $result = $this->_backend->get($id);
     }
     return $result;
 }
Пример #6
0
 /**
  * Checks the availability of a given tag
  *
  * @param string $key
  * @return boolean
  */
 public function exists($key)
 {
     if (null !== $this->cacheAdapter) {
         $prefixedKey = $this->prefixKey($key);
         return $this->cacheAdapter->test($prefixedKey) !== false;
     }
     return false;
 }
Пример #7
0
 /**
  * @param string $file
  * @param bool $fromDefault
  * @return Zend_Config
  * @author Se#
  * @version 0.0.1
  */
 protected function _loadConfig($file, $fromDefault = false)
 {
     // define is default config need
     $default = $fromDefault ? false : $this->_defaultConfig();
     $suffix = strtolower(pathinfo($file, PATHINFO_EXTENSION));
     if ($this->_configCache === null || $suffix == 'php' || $suffix == 'inc') {
         //No need for caching those
         return $default ? $this->_mergeConfigs($default, parent::_loadConfig($file)) : parent::_loadConfig($file);
     }
     $configMTime = filemtime($file);
     $cacheId = $this->_cacheId($file);
     $cacheLastMTime = $this->_configCache->test($cacheId);
     if ($cacheLastMTime !== false && $configMTime < $cacheLastMTime) {
         //Valid cache?
         return $this->_configCache->load($cacheId, true);
     } else {
         $config = parent::_loadConfig($file);
         $this->_configCache->save($config, $cacheId, array(), null);
         return $default ? $this->_mergeConfigs($default, $config) : $config;
     }
 }
Пример #8
0
 /**
  * Get options
  *
  * @return array
  */
 private function _getOptions()
 {
     if (!extension_loaded('apc')) {
         return $this->_makeOptions();
     }
     //@todo GET SESSION/CACHE/LOAD Config
     include_once 'ZLayer/Cache.php';
     include_once 'Zend/Cache.php';
     include_once 'Zend/Cache/Core.php';
     include_once 'Zend/Cache/Backend/Apc.php';
     $configCache = new Zend_Cache_Core(array('automatic_serialization' => true));
     $backend = new Zend_Cache_Backend_Apc();
     $configCache->setBackend($backend);
     //$configMTime = filemtime($file);
     $cacheId = ZLayer_Cache::id("application");
     $configCache->remove($cacheId);
     if ($configCache->test($cacheId) !== false) {
         return $configCache->load($cacheId, true);
     } else {
         $array = $this->_makeOptions();
         $configCache->save($array, $cacheId, array(), null);
         return $array;
     }
 }
 /**
  * login to Tine 2.0 installation 
  * 
  * @param string $loginname
  * @param string $password
  * @return array decoded JSON responce
  * @throws Zend_Service_Exception
  */
 public function login($loginname, $password)
 {
     $this->setSkipSystemLookup(true);
     $response = $this->call('Tinebase.login', array('username' => $loginname, 'password' => $password));
     if ($response['success'] !== true) {
         throw new Zend_Service_Exception($response['errorMessage']);
     }
     $this->_jsonKey = $response['jsonKey'];
     $this->_account = $response['account'];
     $this->getHttpClient()->setHeaders('X-Tine20-JsonKey', $this->_jsonKey);
     if ($this->_cache instanceof Zend_Cache_Core) {
         if ($this->_cache->test('tine20PrivateSMD')) {
             $smd = $this->_cache->load('tine20PrivateSMD');
             $this->getIntrospector()->setSMD($smd);
         } else {
             $smd = $this->getIntrospector()->fetchSMD();
             $this->_cache->save($smd, 'tine20PrivateSMD');
         }
     } else {
         $this->getIntrospector()->fetchSMD();
     }
     $this->setSkipSystemLookup(false);
     return $response;
 }
Пример #10
0
 /**
  * Test if an entry exists in the cache.
  *
  * @param string $id cache id The cache id of the entry to check for.
  *
  * @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.
  */
 protected function doContains($id)
 {
     return $this->cache->test($this->prefix . md5($id));
 }
 protected function assertKeys(Zend_Cache_Core $cache, array $keys)
 {
     foreach ($keys as $key) {
         $this->assertTrue($cache->test($key) > 0);
     }
 }
 /**
  *
  * @param string $id
  * @return boolean
  */
 protected function _doContains($id)
 {
     return (bool) $this->_zendCache->test($id);
 }
Пример #13
0
 /**
  * {@inheritdoc}
  */
 public function test($identifier)
 {
     return $this->_frontend->test($this->_unifyId($identifier));
 }
Пример #14
0
 /**
  * @return Controlador
  */
 private function _check()
 {
     if (is_null($this->usuario) && !strstr($this->_view, 'captcha.php') && !strstr($this->_view, 'modelos/login/login.php') && !strstr($this->_view, 'recuperar_senha_usuario.php') && !strstr($this->_view, 'webservices/') && !strstr($this->_view, 'logoff.php') && !strstr($this->_view, 'modelos/prazos/verificar_prazos_pendentes.php') && !strstr($this->_view, 'modelos/usuarios/recuperar_senha_usuario.php')) {
         $this->_view = 'identificacao.php';
     }
     if (!is_null($this->usuario)) {
         if (is_null($this->usuario->ID_UNIDADE) && $this->_view != 'logoff.php') {
             if (count($this->unidades) > 1) {
                 $this->_view = 'usuario_selecionar_unidade.php';
             } else {
                 if (count($this->unidades) == 1) {
                     $this->usuario->DIRETORIA = current($this->unidades)->NOME;
                     $this->usuario->ID_UNIDADE = current($this->unidades)->ID;
                     $this->usuario->ID_UNIDADE_ORIGINAL = current($this->unidades)->ID;
                     Zend_Auth::getInstance()->getStorage()->write($this->usuario);
                     $this->_prepareAcl();
                 } else {
                     $this->_view = 'usuario_sem_unidade_vinculada.php';
                 }
             }
         }
         if ($this->_view == '' || $this->_view == '/' || $this->_view == 'identificacao.php') {
             $this->_view = 'sistemas.php';
         }
         /*
          * Pegar o id do recurso que o usuário está tentando acessar
          * isso não deve ser feito no caso do recurso ser login ou logoff
          */
         if (substr_count($this->_view, '/') == 0 && array_search($this->_view, $this->_excessoes) === false) {
             $name_recurso = str_replace('.', '_', $this->_view);
             if (!$this->cache->test('recurso_' . $name_recurso)) {
                 $this->recurso = DaoRecurso::getRecursoByUrl($this->_view);
                 if (isset($this->recurso->id)) {
                     $this->cache->save($this->recurso, 'recurso_' . $name_recurso, array('recurso_' . $this->recurso->id, 'paginas'));
                 } else {
                     $this->recurso = null;
                 }
             } else {
                 $this->recurso = $this->cache->load('recurso_' . $name_recurso);
             }
             /*
              * Verificacao de ACL ocorre abaixo
              * mas não deve ocorrer a menos que o usuário esteja requisitando
              * um recurso contido na pasta interfaces
              * Não existe verificacao de Acl para a pasta modelos/
              */
             if (isset($this->recurso->id)) {
                 if ($this->acl->has($this->recurso->id)) {
                     if (!$this->acl->isAllowed($this->usuario->ID, $this->recurso)) {
                         $this->_view = 'denied.php';
                     } else {
                         // nao recusou o acl, montar os submenus do recurso
                         $this->botoes = Util::getMenus($this->usuario, $this->recurso, $this->acl);
                     }
                 } else {
                     // TODO: Aqui negará novamente, pois se o recurso não existe no acl
                     // deve ser negado por segurança
                     $this->_view = 'denied.php';
                 }
             } else {
                 $this->_view = 'denied.php';
             }
         }
     }
     return $this;
 }
Пример #15
0
 /**
  * Test if a cache is available for the given id 
  *
  * @param string $id cache id
  * @return boolean true is a cache is available, false else
  */
 public function test($id)
 {
     $lastModified = parent::test($id);
     if ($lastModified) {
         if ($lastModified > $this->_masterFile_mtime) {
             return $lastModified;
         }
     }
     return false;
 }
Пример #16
0
 /**
  * Возвращает список виджетов для текущего набора и текущего пользователя
  *  
  * @return array
  */
 private function _getWidgetsList()
 {
     /**
      * Определяем идентификатор кеша
      */
     $cacheid = 'widgetslist_' . $this->_params['WidgetSetId'] . '_' . $this->_getCacheIdentity();
     /**
      * Проверяем наличие записи в кеше
      */
     if ($this->_cache->test($cacheid)) {
         return $this->_cache->load($cacheid);
         /**
          * Если записи в кеше нет, то делаем выборку списка виджетов
          */
     } else {
         /**
          * Получаем информацию о наборе виджетов
          */
         if ($SetInfo = $this->getWidgetsSetInfo($this->_params['WidgetSetId'])) {
             /**
              * Распаковываем виджеты набора
              * @todo Подумать над снижением кол-ва запросов к базе
              */
             $SetInfo['widgets'] = Zend_Json::decode($SetInfo['widgets']);
             foreach ($SetInfo['widgets'] as $layoutcode => $widget) {
                 foreach ($widget as $key => $params) {
                     $SetInfo['widgets'][$layoutcode][$key] = $params = Zend_Json::decode($params);
                     /**
                      * Проверяем права доступа к виджету
                      */
                     if (isset($params['acl']) && is_array($params['acl']) && in_array($this->_usersession->UserData['roleid'], $params['acl'])) {
                         /**
                          * Добавляем фильтр по разделам сайта
                          */
                         if (isset($this->_params['categoryinfo']) && isset($params['showincats']) && is_array($params['showincats'])) {
                             if (in_array($this->_params['categoryinfo']['categoryid'], $params['showincats'])) {
                                 /**
                                  * Получаем информацию о типе виджета
                                  */
                                 if ($TypeInfo = $this->getWidgetTypeInfo($params['typeid'])) {
                                     $SetInfo['widgets'][$layoutcode][$key]['typeinfo'] = $TypeInfo;
                                 }
                             }
                         } else {
                             /**
                              * Получаем информацию о типе виджета
                              */
                             if ($TypeInfo = $this->getWidgetTypeInfo($params['typeid'])) {
                                 $SetInfo['widgets'][$layoutcode][$key]['typeinfo'] = $TypeInfo;
                             }
                         }
                     }
                 }
             }
             // Сохраняем запись в кеше
             $this->_cache->save($SetInfo, $cacheid);
             return $SetInfo;
         }
     }
     return false;
 }
Пример #17
0
 /**
  * Test if a cache is available for the given id
  *
  * @param  string $id Cache id
  * @return int|false Last modified time of cache entry if it is available, false otherwise
  */
 public function test($id)
 {
     $lastModified = parent::test($id);
     if ($lastModified) {
         if ($this->_specificOptions['master_files_mode'] == self::MODE_AND) {
             // MODE_AND
             foreach ($this->_masterFile_mtimes as $masterFileMTime) {
                 if ($masterFileMTime) {
                     if ($lastModified > $masterFileMTime) {
                         return $lastModified;
                     }
                 }
             }
         } else {
             // MODE_OR
             $res = true;
             foreach ($this->_masterFile_mtimes as $masterFileMTime) {
                 if ($masterFileMTime) {
                     if ($lastModified <= $masterFileMTime) {
                         return false;
                     }
                 }
             }
             return $lastModified;
         }
     }
     return false;
 }
Пример #18
0
 /**
  * Test if a cache record exists for the passed id
  *
  * @param string $id cache id
  * @return mixed false (a cache is not available) or "last modified"
  *               timestamp (int) of the available cache record
  */
 protected function _doContains($id)
 {
     return $this->_cache->test($this->_prefix . $id);
 }