本文整理汇总了PHP中Cache::has方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::has方法的具体用法?PHP Cache::has怎么用?PHP Cache::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: project
/**
* 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);
}
示例2: testGetHasExisting
public function testGetHasExisting()
{
$this->cache->set("foo", "bar");
$this->assertEquals("bar", $this->cache->get("foo"));
$this->assertTrue($this->cache->has("foo"));
//test if cache has been written
$this->cache->writeCache()->flush(true);
$this->assertEquals("bar", $this->cache->get("foo"));
}
示例3: embed_gists
public function embed_gists($content)
{
$gists_regex = '/<script[^>]+src="(http:\\/\\/gist.github.com\\/[^"]+)"[^>]*><\\/script>/i';
// remove gists from multiple-post templates
if (Options::get('gistextras__removefrommultiple')) {
if (!in_array(URL::get_matched_rule()->name, array('display_entry', 'display_page'))) {
return preg_replace($gists_regex, '', $content);
}
}
preg_match_all($gists_regex, $content, $gists);
for ($i = 0, $n = count($gists[0]); $i < $n; $i++) {
if (Options::get('gistextras__cachegists')) {
if (Cache::has($gists[1][$i])) {
$gist = Cache::get($gists[1][$i]);
} else {
if ($gist = RemoteRequest::get_contents($gists[1][$i])) {
$gist = $this->process_gist($gist);
Cache::set($gists[1][$i], $gist, 86400);
// cache for 1 day
}
}
} else {
$gist = RemoteRequest::get_contents($gists[1][$i]);
$gist = $this->process_gist($gist);
}
// replace the script tag
$content = str_replace($gists[0][$i], $gist, $content);
}
return $content;
}
示例4: get_exchange_rates
public function get_exchange_rates()
{
// \Cache::forget('money_exchange_rates');
if (\Cache::has('money_exchange_rates')) {
$data = \Cache::get('money_exchange_rates');
} elseif (is_connected("openexchangerates.org")) {
$api_key = "bbc128aa6f3645d78b098f0eef3dd533";
$json = file_get_contents("http://openexchangerates.org/api/latest.json?app_id={$api_key}");
$json = json_decode($json, true);
$data['rates'] = $json['rates'];
$data['base'] = $json['base'];
// $data['json_rates'] = json_encode($json['rates']);
\Cache::add('money_exchange_rates', $data, 360);
\Cache::add('money_exchange_rates_default', $data, 50000);
} else {
$data = \Cache::get('money_exchange_rates_default');
}
$currency_list = \Lst::common('currency1');
$arr["site_name"] = "Ahmed-Badawy.com";
$arr["base"] = $data['base'];
foreach ($currency_list as $key => $val) {
$n = ['short' => $key, "name" => $val, "value" => $data['rates'][$key]];
$arr['rates'][$key] = $n;
}
return $arr;
}
示例5: get
public function get($id, $elequent)
{
$cacheKey = self::CACHE . $id;
if ($elequent) {
return Email::find($id);
}
$cachedData = \Cache::has($cacheKey);
if (empty($cachedData)) {
$email = Email::find($id);
if (!empty($email)) {
$email = $email->toArray();
$email['updated_at'] = date('Y-m-d', strtotime($email['updated_at']));
$email['created_at_formatted'] = date('Y-m-d', strtotime($email['created_at']));
$email['updated_at_formatted'] = date('Y-m-d', strtotime($email['updated_at']));
// unset($country['password']);
//unset($country['code']);
// Set data in cache
\Cache::forever($cacheKey, $email);
return $email;
} else {
return false;
}
} else {
return \Cache::get($cacheKey);
}
}
示例6: get_arrays
/**
* get static data from cache or from remote
*/
private function get_arrays()
{
if (Cache::has('stops')) {
$sn = Cache::get('stops');
extract($sn);
} else {
// vars
$base_url = 'http://api.hannesv.be/';
$endpoint = 'nmbs/stations.json';
$cache_time = 120;
// minutes
// get stop names
$client = new Client($base_url);
$result = $client->get($endpoint)->send()->json();
// start empty
$stop_names = array();
$inverted = array();
// loop
foreach ($result['stations'] as $station) {
$stop_names[(int) $station['sid']] = $station['stop'];
$inverted[$station['stop']] = (int) $station['sid'];
}
// cache result
Cache::put('stops', compact('stop_names', 'inverted'), $cache_time);
}
// return
return array($stop_names, $inverted);
}
示例7: put
/**
* Cache route
*
* @param Route $route
* @param Request $request
* @param Response $response
*/
public function put(Route $route, Request $request, Response $response)
{
$key = $this->makeCacheKey($request->url());
if (!Cache::has($key)) {
Cache::put($key, $response->getContent(), 60);
}
}
示例8: generate
public function generate($args)
{
if (count($args) != 1) {
die(self::$usageMessage);
}
$model = $args[0];
$table = Str::plural(Str::lower($model));
$options = array('Model' => $model, 'Table' => $table, 'DefaultField' => 'text', 'ParentID' => 'parent_id', 'Leaf' => 'leaf');
$r = new ReflectionClass($model);
preg_match_all('#@(.*?)\\n#s', $r->getDocComment(), $annotations);
if (!empty($annotations)) {
foreach ($annotations[0] as $annotation) {
preg_match('#@(?P<name>\\w+)[ ]*(\\([ ]*(?P<value>\\w+)[ ]*\\))?\\n#s', $annotation, $a);
if (array_key_exists($a['name'], $options)) {
$options[$a['name']] = $a['value'];
}
}
}
$columns = DB::query('SHOW columns from ' . $table);
if (Cache::has('ext' . $model, $columns)) {
$was_cached = true;
} else {
Cache::forever('ext' . $model, $columns);
$was_cached = false;
}
// Generate code
$this->generateExtModel($columns, $model, $options);
$this->generateGrid($columns, $model, $options, $was_cached);
$this->generateForm($columns, $model, $options, $was_cached);
$this->generateTree($model, $options, $was_cached);
/**************************************************************/
echo 'Task executed successfully';
}
示例9: generate
/**
* Generate the widget and return it as string
*
* @return string
*/
public function generate()
{
$arrButtons = array('copy', 'delete', 'drag');
// Make sure there is at least an empty array
if (!is_array($this->varValue) || empty($this->varValue)) {
$this->varValue = array('');
}
// Initialize the tab index
if (!\Cache::has('tabindex')) {
\Cache::set('tabindex', 1);
}
$return = '<ul id="ctrl_' . $this->strId . '" class="tl_listwizard">';
// Add input fields
for ($i = 0, $c = count($this->varValue); $i < $c; $i++) {
$return .= '
<li><input type="text" name="' . $this->strId . '[]" class="tl_text" value="' . \StringUtil::specialchars($this->varValue[$i]) . '"' . $this->getAttributes() . '> ';
// Add buttons
foreach ($arrButtons as $button) {
if ($button == 'drag') {
$return .= ' <button type="button" class="drag-handle" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['move']) . '">' . \Image::getHtml('drag.svg') . '</button>';
} else {
$return .= ' <button type="button" data-command="' . $button . '" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['lw_' . $button]) . '">' . \Image::getHtml($button . '.svg') . '</button>';
}
}
$return .= '</li>';
}
return $return . '
</ul>
<script>Backend.listWizard("ctrl_' . $this->strId . '")</script>';
}
示例10: searchTitle
/**
* Search for movie title
*
* @param string $q The search query
*
* @return Response
*/
public function searchTitle($q)
{
// init result array
$result = array();
// trim query
$q = trim($q);
// create slug from query
$q_slug = str_slug('imdb-' . $q);
// check if search is in cache
if (\Cache::has($q_slug)) {
// retrieve item from cache
$item = \Cache::get($q_slug);
// add data to array
$result = array('fromcache' => true, 'data' => $item);
} else {
// url encode query
$q = urlencode($q);
// Use the Imdb Api to search for movie
$imdbResult = json_decode(file_get_contents(sprintf(env('IMDB_SEARCH_TITLE_URL'), $q)));
// only proceed if the most popular title array is filled and at least contains 1 movie
if (isset($imdbResult->title_popular) && is_array($imdbResult->title_popular) && count($imdbResult->title_popular) > 0) {
// extract year from title_description
$year = intval(substr($imdbResult->title_popular[0]->title_description, 0, 4));
// create object for this movie
$item = new ImdbMovie($imdbResult->title_popular[0]->id, $imdbResult->title_popular[0]->title, $year);
// add item to cache for a year
\Cache::add($q_slug, $item, 60 * 24 * 365);
// add data to array
$result = array('fromcache' => false, 'data' => $item);
}
}
// return json formatted response
return response()->json($result);
}
示例11: action_add_template_vars
function action_add_template_vars($theme)
{
$username = Options::get('freshsurf__username');
$password = Options::get('freshsurf__password');
$count = Options::get('freshsurf__count');
if ($username != '' && $password != '') {
if (Cache::has('freshsurf__' . $username)) {
$response = Cache::get('freshsurf__' . $username);
} else {
$request = new RemoteRequest("https://{$username}:{$password}@" . self::BASE_URL . "posts/recent?count={$count}", 'GET', 20);
$request->execute();
$response = $request->get_response_body();
Cache::set('freshsurf__' . $username, $response);
}
$delicious = @simplexml_load_string($response);
if ($delicious instanceof SimpleXMLElement) {
$theme->delicious = $delicious;
} else {
$theme->delicious = @simplexml_load_string('<posts><post href="#" description="Could not load feed from delicious. Is username/password correct?"/></posts>');
Cache::expire('freshsurf__' . $username);
}
} else {
$theme->delicious = @simplexml_load_string('<posts></posts>');
}
}
示例12: render
public function render()
{
$key = md5($this->getPath());
$lastModified = $this->files->lastModified($this->getPath());
$generate = false;
if ($lastModifiedCache = \Cache::get("{$key}.lastmodified", false) !== false && \Cache::has($key)) {
if ($lastModified !== $lastModified) {
$generate = true;
}
} else {
$generate = true;
}
if (config('app.debug')) {
$generate = true;
}
$rendered = '';
if ($generate === true) {
$rendered = $this->parser->parse($this->files->get($this->getPath()));
\Cache::forever($key, $rendered);
\Cache::forever("{$key}.lastmodified", $lastModified);
} else {
$rendered = \Cache::get($key, false);
}
return $rendered;
}
示例13: handleGet
/**
* 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')));
}
}
}
示例14: SitemapBuild
public function SitemapBuild()
{
//return cached sitemap if exsist
if (Cache::has('sitemap')) {
$xml = Cache::get('sitemap');
} else {
$types = Options::get_group(__CLASS__);
//..or generate a new one
$xml = '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="' . $this->get_url() . '/sitemap.xsl"?><urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>';
$xml = new SimpleXMLElement($xml);
if (array_key_exists('any', $types) && $types['any'] || empty($types)) {
// Retrieve all published content, regardless of the type
$content['any'] = Posts::get(array('content_type' => 'any', 'status' => 'published', 'nolimit' => 1));
} else {
// Retreive all published content for select content types
$content['posts'] = Posts::get(array('content_type' => array_keys($types, 1), 'status' => 'published', 'nolimit' => 1));
}
// Add the index page first
$url = $xml->addChild('url');
$url_loc = $url->addChild('loc', Site::get_url('habari'));
// Generate the `<url>`, `<loc>`, `<lastmod>` markup for each post and page.
foreach ($content as $entries) {
foreach ($entries as $entry) {
$url = $xml->addChild('url');
$url_loc = $url->addChild('loc', $entry->permalink);
$url_lastmod = $url->addChild('lastmod', $entry->updated->get('c'));
}
}
$xml = $xml->asXML();
Cache::set('sitemap', $xml);
}
return $xml;
}
示例15: getCache
/**
* Get cached data.
*
* @param string $index
*
* @return bool|array
*/
public function getCache($index)
{
if (\Cache::has($index)) {
return unserialize(\Cache::get($index));
}
return false;
}