Beispiel #1
0
 /**
  * method to clean account cache
  * 
  * @param int $aid
  * 
  * @return true on success, else false
  */
 protected function cleanAccountCache($aid)
 {
     $cache = Billrun_Factory::cache();
     if (empty($cache)) {
         return false;
     }
     $aids = array_unique(array_diff(Billrun_Util::verify_array(explode(',', $aid), 'int'), array(0)));
     $billrunKey = Billrun_Util::getBillrunKey(time());
     $cachePrefix = 'balance_';
     // this is not the action name because it's clear the balance cache
     foreach ($aids as $aid) {
         $cleanCacheKeys = array(Billrun_Util::generateArrayStamp(array_values(array('aid' => $aid, 'subscribers' => array(), 'stamp' => $billrunKey))), Billrun_Util::generateArrayStamp(array_values(array('aid' => $aid, 'subscribers' => null, 'stamp' => (int) $billrunKey))), Billrun_Util::generateArrayStamp(array_values(array('aid' => $aid, 'subscribers' => "", 'stamp' => (int) $billrunKey))), Billrun_Util::generateArrayStamp(array_values(array('aid' => $aid, 'subscribers' => 0, 'stamp' => (int) $billrunKey))));
         foreach ($cleanCacheKeys as $cacheKey) {
             $cache->remove($cacheKey, $cachePrefix);
         }
     }
     return true;
 }
Beispiel #2
0
 /**
  * method to store and fetch by global cache layer
  * 
  * @param type $params params to be used by cache to populate and store
  * 
  * @return mixed the cached results
  */
 protected function cache($params)
 {
     if (!isset($params['stampParams'])) {
         $params['stampParams'] = $params['fetchParams'];
     }
     $cache = Billrun_Factory::cache();
     if (empty($cache)) {
         return $this->fetchData($params['fetchParams']);
     }
     $actionName = $this->getAction();
     $cachePrefix = $this->getCachePrefix();
     $cacheKey = Billrun_Util::generateArrayStamp(array_values($params['stampParams']));
     $cachedData = $cache->get($cacheKey, $cachePrefix);
     if (empty($cachedData)) {
         $cachedData = $this->fetchData($params['fetchParams']);
         $lifetime = Billrun_Factory::config()->getConfigValue('api.cacheLifetime.' . $actionName, $this->getCacheLifeTime());
         $cache->set($cacheKey, $cachedData, $cachePrefix, $lifetime);
     } else {
         Billrun_Factory::log()->log("Fetch data from cache for " . $actionName . " api call", Zend_Log::INFO);
     }
     return $cachedData;
 }
Beispiel #3
0
 /**
  * method to retrieve the cache instance
  * 
  * @return Billrun_Cache
  */
 public static function cache()
 {
     try {
         if (!self::$cache) {
             $args = self::config()->getConfigValue('cache', array());
             if (empty($args)) {
                 return false;
             }
             self::$cache = Billrun_Cache::getInstance($args);
         }
         return self::$cache;
     } catch (Exception $e) {
         Billrun_Factory::log('Cache instance cannot be generated', Zend_Log::ALERT);
     }
     return false;
 }
Beispiel #4
0
 /**
  * method to retrieve the cache instance
  * 
  * @return Billrun_Cache
  */
 public static function cache()
 {
     if (!self::$cache) {
         $args = self::config()->getConfigValue('cache', array());
         if (empty($args)) {
             return false;
         }
         self::$cache = Billrun_Cache::getInstance($args);
     }
     return self::$cache;
 }