get() 공개 메소드

Retrieve value of cache entry
public get ( $key ) : mixed | FALSE
$key string
리턴 mixed | FALSE
예제 #1
0
 /**
  * @param array|bool $dataAcl
  * @dataProvider aclDataProvider
  */
 public function testHasWithAcl($dataAcl)
 {
     $this->initAcl(is_array($dataAcl) ? serialize($dataAcl) : $dataAcl);
     $this->cacheConfig->expects($this->never())->method('test');
     $this->model->get();
     $this->assertTrue($this->model->has());
 }
 public function isLocked($key)
 {
     if ($this->cache->get($key) === false) {
         return false;
     }
     return true;
 }
예제 #3
0
 /**
  * @covers Phossa\Config\Env\Environment::save()
  * @covers Phossa\Config\Env\Environment::get()
  * @covers Phossa\Config\Env\Environment::clear()
  */
 public function testSave()
 {
     $data = ['db' => ['dsn' => 'bingo']];
     $this->object->save($data);
     $this->assertEquals($data, $this->object->get());
     $this->object->clear();
     $this->assertFalse($this->object->get());
 }
예제 #4
0
 /**
  * cache test call
  *
  * @param string $input
  * @return bool
  *
  * @url GET cache
  * @access public
  */
 function testCache($input = '')
 {
     $redis = new Cache('test', 'redis', array());
     $r[] = $redis->get('key');
     $r[] = $redis->set('key', 'value');
     $r[] = $redis->get('key');
     $r[] = $redis->del('key');
     return $r;
 }
예제 #5
0
 public function get($groupName, $identifier, $function = null, $arguments = array())
 {
     $ret = $this->cache->get($groupName, $identifier, $this->lifetime);
     if ($ret == false && $function != null) {
         $ret = call_user_func_array($function, $arguments);
         $this->cache->set($groupName, $identifier, $ret);
     }
     return $ret;
 }
예제 #6
0
 function test_timeout()
 {
     $c = new Cache();
     // test cache expiry
     $c->set('bar', 'asdf', 0, 1);
     $this->assertEquals('asdf', $c->get('bar'));
     sleep(2);
     $this->assertFalse($c->get('bar'));
 }
예제 #7
0
 /**
  * Take a project key and return the properties
  *
  * @param string $identifier
  * @return array
  */
 public function project($identifier)
 {
     if (!$this->cache->has($identifier)) {
         $html = $this->fetch($identifier);
         $project = $this->parse($html);
         $this->cache->set($identifier, $project, $this->expiry);
     }
     return $this->cache->get($identifier);
 }
예제 #8
0
 /**
  * 获取jsticket
  *
  * @return string
  */
 public function getTicket()
 {
     $key = 'overtrue.wechat.jsapi_ticket' . $this->appId;
     return $this->cache->get($key, function ($key) {
         $http = new Http(new AccessToken($this->appId, $this->appSecret));
         $result = $http->get(self::API_TICKET);
         $this->cache->set($key, $result['ticket'], $result['expires_in']);
         return $result['ticket'];
     });
 }
예제 #9
0
 /**
  * 获取颜色列表
  *
  * @return array
  */
 public function lists()
 {
     $key = 'overtrue.wechat.colors';
     return $this->cache->get($key, function ($key) {
         $result = $this->http->get(self::API_LIST);
         $this->cache->set($key, $result['colors'], 86400);
         // 1 day
         return $result['colors'];
     });
 }
예제 #10
0
 /**
  * 获取Token
  *
  * @param bool $forceRefresh
  *
  * @return string
  */
 public function getToken($forceRefresh = false)
 {
     $cacheKey = $this->cacheKey;
     $cached = $this->cache->get($cacheKey);
     if ($forceRefresh || !$cached) {
         $token = $this->getTokenFromServer();
         $this->cache->set($cacheKey, $token['access_token'], $token['expires_in'] - 800);
         return $token['access_token'];
     }
     return $cached;
 }
예제 #11
0
파일: watcher.php 프로젝트: sunblade/core
 /**
  * check $path for updates and update if needed
  *
  * @param string $path
  * @param array $cachedEntry
  * @return boolean true if path was updated
  */
 public function checkUpdate($path, $cachedEntry = null)
 {
     if (is_null($cachedEntry)) {
         $cachedEntry = $this->cache->get($path);
     }
     if ($this->needsUpdate($path, $cachedEntry)) {
         $this->update($path, $cachedEntry);
         return true;
     } else {
         return false;
     }
 }
예제 #12
0
 /**
  * Internal cleaning process.
  *
  * @param boolean $cleanAll
  *
  * @return void
  */
 protected function process($cleanAll = true)
 {
     $key = dba_firstkey($this->cache->getDba());
     while ($key !== false && $key !== null) {
         if (true === $cleanAll) {
             $this->cache->delete($key);
         } else {
             $this->cache->get($key);
         }
         $key = dba_nextkey($this->cache->getDba());
     }
     dba_optimize($this->cache->getDba());
 }
예제 #13
0
파일: Color.php 프로젝트: nutsdo/rp-wechat
 /**
  * 获取颜色列表
  *
  * @return array
  */
 public function lists()
 {
     $key = 'overtrue.wechat.colors';
     // for php 5.3
     $http = $this->http;
     $cache = $this->cache;
     return $this->cache->get($key, function ($key) use($http, $cache) {
         $result = $http->get(self::API_LIST);
         $cache->set($key, $result['colors'], 86400);
         // 1 day
         return $result['colors'];
     });
 }
예제 #14
0
 /**
  * 获取Token
  *
  * @return string
  */
 public function getToken()
 {
     if ($this->token) {
         return $this->token;
     }
     $thisObj = $this;
     return $this->cache->get($this->cacheKey, function () use($thisObj) {
         $params = array('appid' => $thisObj->appId, 'secret' => $thisObj->appSecret, 'grant_type' => 'client_credential');
         $http = new Http();
         $token = $http->get($thisObj::API_TOKEN_GET, $params);
         $thisObj->cache->set($thisObj->cacheKey, $token['access_token'], $token['expires_in']);
         return $thisObj->token = $token['access_token'];
     });
 }
예제 #15
0
 /**
  * Send request to OSM server and return the response.
  *
  * @param string $url       URL
  * @param string $method    GET (default)/POST/PUT
  * @param string $user      user (optional for read-only actions)
  * @param string $password  password (optional for read-only actions)
  * @param string $body      body (optional)
  * @param array  $post_data (optional)
  * @param array  $headers   (optional)
  *
  * @access public
  * @return HTTP_Request2_Response
  * @todo   Consider just returning the content?
  * @throws Services_OpenStreetMap_Exception If something unexpected has
  *                                          happened while conversing with
  *                                          the server.
  */
 public function getResponse($url, $method = HTTP_Request2::METHOD_GET, $user = null, $password = null, $body = null, array $post_data = null, array $headers = null)
 {
     $arguments = array($url, $method, $user, $password, $body, implode(":", (array) $post_data), implode(":", (array) $headers));
     $id = md5(implode(":", $arguments));
     $data = $this->cache->get($id);
     if ($data) {
         $response = new HTTP_Request2_Response();
         $response->setStatus(200);
         $response->setBody($data);
         return $response;
     }
     $response = parent::getResponse($url, $method, $user, $password, $body, $post_data, $headers);
     $this->cache->save($id, $response->getBody());
     return $response;
 }
예제 #16
0
 /**
  * check $path for updates
  *
  * @param string $path
  */
 public function checkUpdate($path)
 {
     $cachedEntry = $this->cache->get($path);
     if ($this->storage->hasUpdated($path, $cachedEntry['mtime'])) {
         if ($this->storage->is_dir($path)) {
             $this->scanner->scan($path, Scanner::SCAN_SHALLOW);
         } else {
             $this->scanner->scanFile($path);
         }
         if ($cachedEntry['mimetype'] === 'httpd/unix-directory') {
             $this->cleanFolder($path);
         }
         $this->cache->correctFolderSize($path);
     }
 }
예제 #17
0
		public static function getByID($ctID, $obj = null) {
			if ($obj == null) {
				$ct = Cache::get('pageTypeByID', $ctID);
				if (is_object($ct)) {
					return $ct;
				}
			}
			
			$db = Loader::db();
			$q = "SELECT ctID, ctHandle, ctName, ctIcon, pkgID from PageTypes where PageTypes.ctID = ?";
			$r = $db->query($q, array($ctID));
			if ($r) {
				$row = $r->fetchRow();
				$r->free();
				if (is_array($row)) {
					$row['mcID'] = $db->GetOne("select cID from Pages where ctID = ? and cIsTemplate = 1", array($row['ctID']));
					$ct = new CollectionType; 
					$ct->setPropertiesFromArray($row);
					$ct->setComposerProperties();
					if ($obj) {
						$ct->limit($obj);
					} else {
						Cache::set('pageTypeByID', $ctID, $ct);
					}
				}
			}
			
			return $ct;
		}
예제 #18
0
 /**
  * Fetch setting
  *
  * @param $key
  * @return null
  */
 public function get($key)
 {
     /**
      * Setup cache key
      */
     $cacheKey = 'setting_' . md5($key);
     /**
      * Check if in cache
      */
     if (\Cache::has($cacheKey)) {
         return \Cache::get($cacheKey);
     }
     /**
      * Fetch from database
      */
     $setting = Setting::where('key', '=', $key)->first();
     /**
      * If a row was found, return the value
      */
     if (is_object($setting) && $setting->getId()) {
         /**
          * Store in cache
          */
         \Cache::forever($cacheKey, $setting->getValue());
         /**
          * Return the data
          */
         return $setting->getValue();
     }
     return null;
 }
예제 #19
0
function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cachetime = 0)
{
    $url = "http://api.openweathermap.org/data/2.5/weather?q=" . $loc . "&appid=" . $appid . "&lang=" . $lang . "&units=" . $units . "&mode=xml";
    $cached = Cache::get('curweather' . md5($url));
    $now = new DateTime();
    if (!is_null($cached)) {
        $cdate = get_pconfig(local_user(), 'curweather', 'last');
        $cached = unserialize($cached);
        if ($cdate + $cachetime > $now->getTimestamp()) {
            return $cached;
        }
    }
    try {
        $res = new SimpleXMLElement(fetch_url($url));
    } catch (Exception $e) {
        info(t('Error fetching weather data.\\nError was: ' . $e->getMessage()));
        return false;
    }
    if ((string) $res->temperature['unit'] === 'metric') {
        $tunit = '°C';
        $wunit = 'm/s';
    } else {
        $tunit = '°F';
        $wunit = 'mph';
    }
    if (trim((string) $res->weather['value']) == trim((string) $res->clouds['name'])) {
        $desc = (string) $res->clouds['name'];
    } else {
        $desc = (string) $res->weather['value'] . ', ' . (string) $res->clouds['name'];
    }
    $r = array('city' => (string) $res->city['name'][0], 'country' => (string) $res->city->country[0], 'lat' => (string) $res->city->coord['lat'], 'lon' => (string) $res->city->coord['lon'], 'temperature' => (string) $res->temperature['value'][0] . $tunit, 'pressure' => (string) $res->pressure['value'] . (string) $res->pressure['unit'], 'humidity' => (string) $res->humidity['value'] . (string) $res->humidity['unit'], 'descripion' => $desc, 'wind' => (string) $res->wind->speed['name'] . ' (' . (string) $res->wind->speed['value'] . $wunit . ')', 'update' => (string) $res->lastupdate['value'], 'icon' => (string) $res->weather['icon']);
    set_pconfig(local_user(), 'curweather', 'last', $now->getTimestamp());
    Cache::set('curweather' . md5($url), serialize($r), CACHE_HOUR);
    return $r;
}
예제 #20
0
파일: m2.php 프로젝트: eeejayg/F5UXP
 /**
 		Retrieve from cache; or save query results to cache if not
 		previously executed
 			@param $query array
 			@param $ttl int
 			@private
 	**/
 private function cache(array $query, $ttl)
 {
     $cmd = json_encode($query, TRUE);
     $hash = 'mdb.' . self::hash($cmd);
     $cached = Cache::cached($hash);
     $db = (string) $this->db;
     $stats =& self::ref('STATS');
     if ($ttl && $cached && $_SERVER['REQUEST_TIME'] - $cached < $ttl) {
         // Gather cached queries for profiler
         if (!isset($stats[$db]['cache'][$cmd])) {
             $stats[$db]['cache'][$cmd] = 0;
         }
         $stats[$db]['cache'][$cmd]++;
         // Retrieve from cache
         return Cache::get($hash);
     } else {
         $result = $this->exec($query);
         if ($ttl) {
             Cache::set($hash, $result, $ttl);
         }
         // Gather real queries for profiler
         if (!isset($stats[$db]['queries'][$cmd])) {
             $stats[$db]['queries'][$cmd] = 0;
         }
         $stats[$db]['queries'][$cmd]++;
         return $result;
     }
 }
예제 #21
0
파일: Config.php 프로젝트: pckg/framework
 public function parseDir($dir)
 {
     if (!$dir) {
         return;
     }
     $cache = new Cache($dir);
     $settings = [];
     if (false && $cache->isBuilt()) {
         $settings = $cache->get();
     } else {
         /**
          * @T00D00
          * We need to parse config directory recursively.
          * defaults.php and env.php needs to be taken differently (as root namespace).
          */
         $files = ["defaults" => $dir . 'config' . path('ds') . "defaults.php", "database" => $dir . 'config' . path('ds') . "database.php", "router" => $dir . 'config' . path('ds') . "router.php", "env" => $dir . 'config' . path('ds') . "env.php"];
         foreach ($files as $key => $file) {
             $content = is_file($file) ? require $file : [];
             if (in_array($key, ['defaults', 'env'])) {
                 $settings = $this->merge($settings, $content);
             } else {
                 $settings[$key] = $content;
             }
         }
     }
     $this->data = $this->merge($this->data, $settings);
 }
예제 #22
0
 public static function getCallsignList()
 {
     $callsign_list = Cache::get('[callsignList]');
     if (is_null($callsign_list)) {
         global $db;
         $sql = 'SELECT channel.chanid, channel.channum, channel.callsign FROM channel';
         if ($_SESSION['guide_favonly']) {
             $sql .= ', channelgroup, channelgroupnames WHERE channel.chanid = channelgroup.chanid AND channelgroup.grpid = channelgroupnames.grpid AND channelgroupnames.name = \'Favorites\' AND';
         } else {
             $sql .= ' WHERE';
         }
         $sql .= ' channel.visible = 1';
         $sql .= ' GROUP BY channel.channum, channel.callsign';
         // Sort
         $sql .= ' ORDER BY ' . ($_SESSION["sortby_channum"] ? '' : 'channel.callsign, ') . '(channel.channum + 0), channel.channum, channel.chanid';
         // sort by channum as both int and string to grab subchannels
         // Query
         $sh = $db->query($sql);
         $callsign_list = array();
         while ($channel_data = $sh->fetch_assoc()) {
             $callsign_list[$channel_data['channum'] . ':' . $channel_data['callsign']] = $channel_data['chanid'];
         }
         Cache::set('[callsignList]', $callsign_list);
     }
     return $callsign_list;
 }
예제 #23
0
 private function _setModuleList()
 {
     if (\Cache::has('modules.backend.list')) {
         $this->_moduleList = \Cache::get('modules.backend.list');
         return;
     }
     $moduleDir = app_path() . '/../modules/';
     $result = array();
     if ($handle = opendir($moduleDir)) {
         while (false !== ($dir = readdir($handle))) {
             if ($dir != '.' && $dir != '..') {
                 if (is_dir($moduleDir . $dir)) {
                     $backendData = false;
                     if (file_exists($moduleDir . $dir . '/backend.json')) {
                         $backendData = json_decode(file_get_contents($moduleDir . $dir . '/backend.json'));
                     }
                     $result[] = ['name' => $dir, "dir" => $moduleDir . $dir, 'backend' => $backendData];
                 }
             }
         }
         closedir($handle);
     }
     $this->_moduleList = $result;
     \Cache::forever('modules.backend.list', $result);
 }
예제 #24
0
	public function details($params){
		//Set top carousel
		$carousel = $this->db->getGroupsCarouselDetails($params['detail']);
		parent::set('carouselImage', $carousel);
		parent::set('carouselFolder', 'accomodation');
		parent::set('carouselAction', 'winter');
		parent::set('carouselPage', 'accomodation_id');
		
		//Main table
		if(!Cache::get(array('key' => 'accType'.$params['group']))){
			$output = $this->db->getAccType($params);
			Cache::set(array('key' => 'accType'.$params['group'], 'data' => $output));
		}else $output = Cache::get(array('key' => 'accType'.$params['group']));
		parent::set('accType', $output);
		
		//Accomodation
		if(!Cache::get(array('key' => 'oneAccom'.$params['detail']))){
			$output = $this->db->getOneAcc($params);
			Cache::set(array('key' => 'oneAccom'.$params['detail'], 'data' => $output));
		}else $output = Cache::get(array('key' => 'oneAccom'.$params['detail']));
		parent::set('accom', $output);
		
		//Active page
		parent::set('active', 'zimovanja');
		//Params
		parent::set('params', $params);

		parent::set('front', $this->db->getDescriptionAndKeywords('accomodations', $params['detail']));
	} 
예제 #25
0
파일: Lock.php 프로젝트: jasny/Q
 /**
  * Get the key that fits this lock.
  *
  * @return string
  */
 public function getKey()
 {
     if (!isset($this->info)) {
         $this->info = (array) $this->store->get("lock:" . $this->name);
     }
     return isset($this->info['key']) ? $this->info['key'] : null;
 }
예제 #26
0
 /**
  * Get cached data.
  *
  * @param string $index
  *
  * @return bool|array
  */
 public function getCache($index)
 {
     if (\Cache::has($index)) {
         return unserialize(\Cache::get($index));
     }
     return false;
 }
예제 #27
0
 /**
  * Asks the module to handle a GET (Read) request
  *
  * @param $view
  * @param $args
  * @return Response
  */
 protected function handleGet($view, $args)
 {
     $artist = $view;
     if (!isset($artist)) {
         return new Response(array('message' => "The Hive Radio music artist cover API version {$this->VERSION}", 'usage' => "cover/[artist]"), 200);
     } else {
         if (\Cache::has("artist_cover_{$artist}")) {
             return $this->buildImageResponse(\Cache::get("artist_cover_{$artist}"));
         } else {
             $youtube_response = file_get_contents("https://www.googleapis.com/youtube/v3/search?q={$artist}&key=" . \Config::get('icebreath.covers.youtube_api_key') . "&fields=items(id(kind,channelId),snippet(thumbnails(medium)))&part=snippet,id");
             $youtube_json = json_decode($youtube_response, true);
             $items = $youtube_json['items'];
             $youtube_source = null;
             for ($i = 0; $i < sizeof($items); $i++) {
                 if ((string) $items[$i]["id"]["kind"] != "youtube#channel") {
                     continue;
                 } else {
                     $youtube_source = $items[$i]["snippet"]["thumbnails"]["medium"]["url"];
                     break;
                 }
             }
             if (isset($youtube_source) && !empty($youtube_source)) {
                 $data = file_get_contents($youtube_source);
                 $expiresAt = Carbon::now()->addHours(\Config::get('icebreath.covers.cache_time'));
                 \Cache::put("artist_cover_{$artist}", $data, $expiresAt);
                 return $this->buildImageResponse($data);
             }
             return $this->buildImageResponse(\File::get(base_path() . '/' . \Config::get('icebreath.covers.not_found_img')));
         }
     }
 }
예제 #28
0
 public function settings($key = false)
 {
     if (!$key) {
         return \Cache::get('settings');
     }
     return \Cache::get('settings.' . $key);
 }
 public function findByLocale($locale)
 {
     if ($this->cacheEnabled) {
         $data = \Cache::get($this->getLocaleCacheKey($locale));
         if (!empty($data)) {
             return $data;
         }
     }
     $siteConfiguration = SiteConfiguration::whereLocale($locale)->first();
     if (!empty($siteConfiguration)) {
         if ($this->cacheEnabled) {
             \Cache::put($this->getLocaleCacheKey($locale), $siteConfiguration, $this->cacheLifeTime);
         }
         return $siteConfiguration;
     }
     $siteConfiguration = SiteConfiguration::whereLocale(\Config::get('app.locale'))->first();
     if (!empty($siteConfiguration)) {
         if ($this->cacheEnabled) {
             \Cache::put($this->getLocaleCacheKey($locale), $siteConfiguration, $this->cacheLifeTime);
         }
         return $siteConfiguration;
     }
     $siteConfiguration = SiteConfiguration::orderBy('id', 'asc')->first();
     if ($this->cacheEnabled) {
         \Cache::put($this->getLocaleCacheKey($locale), $siteConfiguration, $this->cacheLifeTime);
     }
     return $siteConfiguration;
 }
예제 #30
0
파일: photo.php 프로젝트: rezaprima/icms
 public function get($id = 0, $useCache = true)
 {
     if (!$id) {
         $id =& $this->id;
     }
     if ($useCache && ($cache = Cache::get($id))) {
         return $cache;
     }
     parent::get($id, !USE_CACHE);
     $this->photos = array();
     $i = 0;
     if (!is_array($this->files['photo'])) {
         return $this;
     }
     foreach ($this->files['photo'] as &$f) {
         $f->main =& Image::createThumbnail($f->name, $this->folder->config['imgWidth']);
         $f->thumb =& Image::createThumbnail($f->name, $this->folder->config['imgThumbWidth']);
         if (++$i == 1) {
             $f->fpthumb =& Image::createThumbnail($f->name, $this->folder->config['fpThumbWidth']);
         }
         $this->photos[] = $f;
     }
     if ($this->pub_on > 0) {
         Cache::set($id, $this);
     }
     return $this;
 }