Example #1
0
 /**
  * Testing the set()/get()/delete() methods.
  *
  * @since 2.0
  * @dataProvider getCacheProviders
  */
 public function testSetGetDelete($provider)
 {
     $cache = CacheProviderFactory::getInstance($provider);
     $cached = array('value' => 5);
     $cache->set('cached', $cached);
     $this->assertEquals(5, $cache->get('cached')['value'], 'Testing the set/get methods');
     $cached = array('value' => 'five');
     $cache->set('cached', $cached);
     $this->assertEquals('five', $cache->get('cached')['value'], 'Testing the set/get methods');
     $cache->delete('cached');
     $this->assertFalse($cache->get('cached'), 'Testing the delete method');
 }
Example #2
0
 /**
  * Constructor.
  *
  * @param $limit The maximum amount of tags to include in the cloud.
  * @param $cacheKey Set this optional value to attempt to store the tag cloud array in the available cache for 24hrs (cache.provider.name).
  *
  * @since 1.0
  */
 public function __construct($limit, $cacheKey = '')
 {
     $config = ConfigProvider::getInstance();
     self::$logger = new Logger('TagCloud');
     if ($cacheKey != '' && $config->get('cache.provider.name') != '') {
         $cache = CacheProviderFactory::getInstance($config->get('cache.provider.name'));
         $this->popTags = $cache->get($cacheKey);
         // cache look-up failed, so add it for the next time
         if (!$this->popTags) {
             self::$logger->debug('Cache lookup on the key [' . $cacheKey . '] failed, regenerating popular tags...');
             $this->popTags = Tag::getPopularTagsArray($limit);
             $cache->set($cacheKey, $this->popTags, 86400);
         } else {
             $this->popTags = array_slice($this->popTags, 0, $limit);
             self::$logger->debug('Cache lookup on the key [' . $cacheKey . '] succeeded');
         }
     } else {
         $this->popTags = Tag::getPopularTagsArray($limit);
     }
 }
Example #3
0
 /**
  * Add the tag search matches to the cache.
  *
  * @since 1.2.4
  */
 public function addToCache($key, $matches)
 {
     $config = ConfigProvider::getInstance();
     try {
         $cache = CacheProviderFactory::getInstance($config->get('cache.provider.name'));
         $cache->set($key, $matches, 86400);
         // cache search matches for a day
     } catch (\Exception $e) {
         self::$logger->error('Error while attempting to store a search matches array to the [' . $config->get('cache.provider.name') . '] 
             instance: [' . $e->getMessage() . ']');
     }
 }
Example #4
0
 /**
  * Attempts to load the business object from the configured cache instance.
  *
  * @since 1.1
  *
  * @return bool
  */
 public function loadFromCache()
 {
     self::$logger->debug('>>loadFromCache()');
     $config = ConfigProvider::getInstance();
     try {
         $cache = CacheProviderFactory::getInstance($config->get('cache.provider.name'));
         $BO = $cache->get(get_class($this) . '-' . $this->getOID());
         if (!$BO) {
             self::$logger->debug('Cache miss on key [' . get_class($this) . '-' . $this->getOID() . ']');
             self::$logger->debug('<<loadFromCache: [false]');
             return false;
         } else {
             // get the class attributes
             $reflection = new ReflectionClass(get_class($this));
             $properties = $reflection->getProperties();
             foreach ($properties as $propObj) {
                 $propName = $propObj->name;
                 // filter transient attributes
                 if (!in_array($propName, $this->transientAttributes)) {
                     $this->set($propName, $BO->get($propName, true));
                 } elseif (!$propObj->isPrivate() && isset($this->{$propName}) && $this->{$propName} instanceof Relation) {
                     $prop = $this->getPropObject($propName);
                     // handle the setting of ONE-TO-MANY relation values
                     if ($prop->getRelationType() == 'ONE-TO-MANY') {
                         $this->set($propObj->name, $this->getOID());
                     }
                 }
             }
             self::$logger->debug('<<loadFromCache: [true]');
             return true;
         }
     } catch (Exception $e) {
         self::$logger->error('Error while attempting to load a business object from [' . $config->get('cache.provider.name') . ']
          instance: [' . $e->getMessage() . ']');
         self::$logger->debug('<<loadFromCache: [false]');
         return false;
     }
 }
Example #5
0
    /**
     * Remove the tag search matches from the cache.
     *
     * @since 1.2.4
     */
    protected function after_save_callback()
    {
        $config = ConfigProvider::getInstance();
        if ($config->get('cache.provider.name') != '') {
            try {
                $cache = CacheProviderFactory::getInstance($config->get('cache.provider.name'));
                $cache->delete($this->get('content'));
            } catch (\Exception $e) {
                self::$logger->error('Error while attempting to remove search matches array from the [' . $config->get('cache.provider.name') . '] 
	      			instance: [' . $e->getMessage() . ']');
            }
        }
    }