コード例 #1
0
 public static function cacheTree($path, $force = false)
 {
     // split path into array
     if (is_string($path)) {
         $path = Site::splitPath($path);
     }
     // check if this tree has already been cached
     $cacheKey = 'cacheTree:' . implode('/', $path);
     if (!Site::$autoPull || !$force && Cache::fetch($cacheKey)) {
         return 0;
     }
     Cache::store($cacheKey, true);
     // get tree map from parent
     $remoteTree = Emergence::resolveCollectionFromParent($path);
     if (!$remoteTree) {
         return 0;
     }
     $filesResolved = 0;
     $startTime = time();
     foreach ($remoteTree['files'] as $remotePath => $remoteFile) {
         $node = Site::resolvePath($remotePath);
         if ($node && $node->Timestamp >= $startTime) {
             $filesResolved++;
         }
     }
     return $filesResolved;
 }
コード例 #2
0
ファイル: Redirect.php プロジェクト: tolik505/bl
 protected function setUrlToCache()
 {
     $url = $this->findUrlFromDB();
     $cache = new \Cache(['path' => __DIR__ . '/../runtime/redirectCache/', 'name' => 'default', 'extension' => '.cache']);
     $cache->store($this->currentUrl, $url);
     return $url;
 }
コード例 #3
0
 public static function stats()
 {
     $player = self::get_user_logged_in();
     $url = $_SERVER['REQUEST_URI'];
     $stripped_url = preg_replace("/[^A-Za-z0-9 ]/", '', $url);
     if ($player) {
         $stripped_url .= $player->playerid;
     }
     // Fetch page from cache
     $cached_page = Cache::getPage($stripped_url);
     if ($cached_page != null && Cache::on()) {
         // Use cached page (which is up to date because outdated pages are deleted)
         echo $cached_page;
     } else {
         // Make page from scratch
         $high_scores = null;
         if ($player) {
             $high_scores = Game::player_high_scores($player->playerid);
         }
         $game_count = Game::count_all();
         $throw_count = Score::count_all();
         $latest_game = Game::latest_game();
         $popular_courses = Course::popular_courses_all_players();
         $page_html = View::make("stats/stats.html", array('game_count' => $game_count, 'throw_count' => $throw_count, 'latest_game' => $latest_game, 'popular_courses' => $popular_courses, 'player' => $player, 'high_scores' => $high_scores));
         if (Cache::on()) {
             // Don't include the page message in the cached file
             $page_html = Cache::strip_tags_content($page_html, "message-success");
             Cache::store($stripped_url, $page_html);
         }
     }
 }
コード例 #4
0
ファイル: cache.php プロジェクト: claremontdesign/zbase
/**
 * Return the current cache driver
 * @return string
 */
function zbase_cache_driver($store = null)
{
    if (is_null($store)) {
        return \Cache::driver();
    }
    return \Cache::store($store);
}
コード例 #5
0
ファイル: feeds.php プロジェクト: semul/Osclass
function osc_latestTweets($num = 5)
{
    require_once osc_lib_path() . 'osclass/classes/Cache.php';
    $cache = new Cache('admin-twitter', 900);
    if ($cache->check()) {
        return $cache->retrieve();
    }
    $list = array();
    $content = osc_file_get_contents('https://twitter.com/statuses/user_timeline/osclass.rss');
    if ($content) {
        $xml = simplexml_load_string($content);
        if (isset($xml->error)) {
            return $list;
        }
        $count = 0;
        foreach ($xml->channel->item as $item) {
            $list[] = array('link' => strval($item->link), 'title' => strval($item->title), 'pubDate' => strval($item->pubDate));
            $count++;
            if ($count == $num) {
                break;
            }
        }
    }
    $cache->store($list);
    return $list;
}
コード例 #6
0
 public function __construct($id = null, $enable_hook = true)
 {
     $this->class_name = get_class($this);
     if (!Object::$db) {
         Object::$db = Db::getInstance();
     }
     self::$is_cache_enabled = defined('OBJECT_CACHE_ENABLE') ? OBJECT_CACHE_ENABLE : false;
     if (isset($id) && Validate::isUnsignedId($id)) {
         $cache_id = $this->class_name . self::CACHE_PREFIX_MODEL . (int) $id;
         if (!Cache::isStored($cache_id)) {
             $sql = new DbQuery();
             $sql->from($this->def['table'], 'a');
             $sql->where('a.' . $this->def['primary'] . '=' . (int) $id);
             if ($object_datas = Object::$db->getRow($sql)) {
                 Cache::store($cache_id, $object_datas);
             }
         } else {
             $object_datas = Cache::retrieve($cache_id);
         }
         if ($object_datas) {
             $this->id = (int) $id;
             foreach ($object_datas as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
         if ($enable_hook && method_exists($this, 'extraConstruct')) {
             $this->extraConstruct();
         }
     }
 }
コード例 #7
0
ファイル: UI.php プロジェクト: jonatanolofsson/heisasolidbase
    function render($cachename = false)
    {
        $out = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sv" lang="sv">
<head><title>Kyrkorna i Linköping</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <meta name="description" content="startsida" />
    <link href="style.css" type="text/css" rel="stylesheet" />
</head><body><h1>Linköpings kyrkor</h1>Välkommen till denna sida för att se vad som händer i Linköpings kyrkor. Om du saknar nån kyrka, eller ser något som inte funkar, skicka ett mail till min gmail, "jonatan.olofsson" at.. osv. (@gmail.com).<br \\>För den intresserade finns källkod på <a href="http://github.com/jonatanolofsson/heisasolidbase">github</a>';
        $meetings = array();
        foreach ($this->churches as $church) {
            $meetings = array_merge($meetings, self::get_all($church));
        }
        usort($meetings, array('UI', 'sorting'));
        $start = time() - 60 * 60;
        $newday = true;
        $newmonth = true;
        $lastday = false;
        $lastmonth = false;
        foreach ($meetings as $meeting) {
            if ($meeting['when'] < $start) {
                continue;
            }
            if (date('Ym', $meeting['when']) != $lastmonth) {
                if ($lastmonth != false) {
                    $out .= '</div>';
                }
                $out .= '<div class="month"><h2>' . strftime('%B', $meeting['when']) . '</h2>';
                $lastmonth = date('Ym', $meeting['when']);
            }
            if (date('Ymd', $meeting['when']) != $lastday) {
                if ($lastday != false) {
                    $out .= '</ul></div>';
                }
                $out .= '<div class="day"><h3>' . strftime('%a, %e', $meeting['when']) . '</h3><ul class="meetings">';
                $lastday = date('Ymd', $meeting['when']);
            }
            $out .= '<li class="meeting">' . strftime('%H:%M', $meeting['when']) . ' - ' . $meeting['what'];
            $out .= '<a href="' . $meeting['church']['url'] . '" class="church">' . $meeting['church']['name'] . '</a>';
            if ($meeting['info'] || $meeting['where']) {
                $out .= '<div class="info">';
                if ($meeting['where']) {
                    $out .= '<span class="where">' . strip_tags($meeting['where'], '<p><a><b><em>') . '</span>';
                }
                if ($meeting['info']) {
                    $out .= strip_tags($meeting['info'], '<p><a><b><em>');
                }
                $out .= '</div>';
            }
            //if($meeting['extra']) $out .= '<div class="extra">'.$meeting['extra'].'</div>';
            $out .= '</li>';
        }
        $out .= '</div></div></body></html>';
        if ($cachename) {
            Cache::store($cachename, $out);
        }
        print $out;
    }
コード例 #8
0
    /**
     * Load ObjectModel
     * @param $id
     * @param $id_lang
     * @param $entity ObjectModel
     * @param $entity_defs
     * @param $id_shop
     * @param $should_cache_objects
     * @throws PrestaShopDatabaseException
     */
    public function load($id, $id_lang, $entity, $entity_defs, $id_shop, $should_cache_objects)
    {
        // Load object from database if object id is present
        $cache_id = 'objectmodel_' . $entity_defs['classname'] . '_' . (int) $id . '_' . (int) $id_shop . '_' . (int) $id_lang;
        if (!$should_cache_objects || !Cache::isStored($cache_id)) {
            $sql = new DbQuery();
            $sql->from($entity_defs['table'], 'a');
            $sql->where('a.`' . bqSQL($entity_defs['primary']) . '` = ' . (int) $id);
            // Get lang informations
            if ($id_lang && isset($entity_defs['multilang']) && $entity_defs['multilang']) {
                $sql->leftJoin($entity_defs['table'] . '_lang', 'b', 'a.`' . bqSQL($entity_defs['primary']) . '` = b.`' . bqSQL($entity_defs['primary']) . '` AND b.`id_lang` = ' . (int) $id_lang);
                if ($id_shop && !empty($entity_defs['multilang_shop'])) {
                    $sql->where('b.`id_shop` = ' . (int) $id_shop);
                }
            }
            // Get shop informations
            if (Shop::isTableAssociated($entity_defs['table'])) {
                $sql->leftJoin($entity_defs['table'] . '_shop', 'c', 'a.`' . bqSQL($entity_defs['primary']) . '` = c.`' . bqSQL($entity_defs['primary']) . '` AND c.`id_shop` = ' . (int) $id_shop);
            }
            if ($object_datas = Db::getInstance()->getRow($sql)) {
                if (!$id_lang && isset($entity_defs['multilang']) && $entity_defs['multilang']) {
                    $sql = 'SELECT *
							FROM `' . bqSQL(_DB_PREFIX_ . $entity_defs['table']) . '_lang`
							WHERE `' . bqSQL($entity_defs['primary']) . '` = ' . (int) $id . ($id_shop && $entity->isLangMultishop() ? ' AND `id_shop` = ' . (int) $id_shop : '');
                    if ($object_datas_lang = Db::getInstance()->executeS($sql)) {
                        foreach ($object_datas_lang as $row) {
                            foreach ($row as $key => $value) {
                                if ($key != $entity_defs['primary'] && array_key_exists($key, $entity)) {
                                    if (!isset($object_datas[$key]) || !is_array($object_datas[$key])) {
                                        $object_datas[$key] = array();
                                    }
                                    $object_datas[$key][$row['id_lang']] = $value;
                                }
                            }
                        }
                    }
                }
                $entity->id = (int) $id;
                foreach ($object_datas as $key => $value) {
                    if (array_key_exists($key, $entity)) {
                        $entity->{$key} = $value;
                    } else {
                        unset($object_datas[$key]);
                    }
                }
                if ($should_cache_objects) {
                    Cache::store($cache_id, $object_datas);
                }
            }
        } else {
            $object_datas = Cache::retrieve($cache_id);
            if ($object_datas) {
                $entity->id = (int) $id;
                foreach ($object_datas as $key => $value) {
                    $entity->{$key} = $value;
                }
            }
        }
    }
コード例 #9
0
ファイル: RssReader.php プロジェクト: pscheit/psc-cms
 /**
  *
  */
 protected function getURLContents()
 {
     if (isset($this->cache) && !$this->refresh) {
         $contents = $this->cache->load('URLContents', $loaded);
         if ($loaded) {
             return $contents;
         }
     }
     $contents = $this->request->init()->process();
     if ($contents === FALSE) {
         throw new Exception('URL konnte nicht gelesen werden: ' . Code::varInfo($this->request->getURL()));
     }
     if (isset($this->cache)) {
         $this->cache->store('URLContents', $contents);
     }
     return $contents;
 }
コード例 #10
0
 public function getBrowserInfoFromAgent($browscap, $agent)
 {
     if (Cache::store('redis')->has($agent)) {
         return json_decode(Cache::store('redis')->get($agent), true);
     }
     $browser_info = json_encode($browscap->getBrowser($agent));
     //dd($browser_info);
     Cache::store('redis')->put($agent, $browser_info, 10);
     return json_decode($browser_info, true);
 }
コード例 #11
0
ファイル: idealist.php プロジェクト: ryunhe/everidea
 public function __construct($filter, $start, $count)
 {
     $cache = new Cache('note_list', false);
     if (!($metaList = $cache->fetch(compact('filter', 'start', 'count')))) {
         $metaList = Evernote::_noteStore()->findNotesMetadata(AUTH_TOKEN, $filter, $start, $count, new EDAM\NoteStore\NotesMetadataResultSpec());
         $cache->store($metaList);
     }
     $this->_metaList = $metaList;
     $this->total = $metaList->totalNotes;
 }
コード例 #12
0
ファイル: TaxRule.php プロジェクト: jpodracky/dogs
 /**
  * @param int $id_tax
  * @return bool
  */
 public static function isTaxInUse($id_tax)
 {
     $cache_id = 'TaxRule::isTaxInUse_' . (int) $id_tax;
     if (!Cache::isStored($cache_id)) {
         $result = (int) Db::getInstance()->getValue('SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'tax_rule` WHERE `id_tax` = ' . (int) $id_tax);
         Cache::store($cache_id, $result);
         return $result;
     }
     return Cache::retrieve($cache_id);
 }
コード例 #13
0
ファイル: ps-cli_utils.php プロジェクト: xego/ps-cli
 public static function ps_cli_init_admin_context()
 {
     $context = Context::getContext();
     // todo: load admin list and pick from it instead of assuming there's a user '1
     $context->employee = new Employee(PS_CLI_EMPLOYEE::get_any_superadmin_id());
     // some controllers die with fatal error if not set
     Cache::store('isLoggedBack' . $context->employee->id, true);
     $context->shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
     // load a generic front controller by default
     $context->controller = new FrontController();
 }
コード例 #14
0
ファイル: user.php プロジェクト: ryunhe/everidea
 public function load($token)
 {
     if (!empty($token)) {
         $cache = new Cache('user');
         if (!($user = $cache->fetch($token))) {
             $user = self::_userStore()->getUser($token);
             $cache->store($user);
         }
         $this->user = $user;
     }
     return $this;
 }
コード例 #15
0
ファイル: notebook.php プロジェクト: ryunhe/everidea
 public function load($guid)
 {
     if (!empty($guid)) {
         $cache = new Cache('notebook');
         if (!($notebook = $cache->fetch($guid))) {
             $notebook = self::_noteStore()->getNotebook(AUTH_TOKEN, $guid);
             $cache->store($notebook);
         }
         $this->notebook = $notebook;
     }
     return $this;
 }
コード例 #16
0
    /**
     * Get all available geographical zones
     *
     * @param bool $active
     * @return array Zones
     */
    public static function getZones($active = false)
    {
        $cache_id = 'Zone::getZones_' . (bool) $active;
        if (!Cache::isStored($cache_id)) {
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
				SELECT *
				FROM `' . _DB_PREFIX_ . 'zone`
				' . ($active ? 'WHERE active = 1' : '') . '
				ORDER BY `name` ASC
			');
            Cache::store($cache_id, $result);
        }
        return Cache::retrieve($cache_id);
    }
コード例 #17
0
ファイル: OrderState.php プロジェクト: dev-lav/htdocs
    /**
     * Get all available order states
     *
     * @param integer $id_lang Language id for state name
     * @return array Order states
     */
    public static function getOrderStates($id_lang)
    {
        $cache_id = 'OrderState::getOrderStates_' . (int) $id_lang;
        if (!Cache::isStored($cache_id)) {
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
			SELECT *
			FROM `' . _DB_PREFIX_ . 'order_state` os
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = ' . (int) $id_lang . ')
			WHERE deleted = 0
			ORDER BY `name` ASC');
            Cache::store($cache_id, $result);
        }
        return Cache::retrieve($cache_id);
    }
コード例 #18
0
 /**
  * Return the tax calculator associated to this address.
  *
  * @return TaxCalculator
  */
 public function getTaxCalculator()
 {
     static $tax_enabled = null;
     if (isset($this->tax_calculator)) {
         return $this->tax_calculator;
     }
     if ($tax_enabled === null) {
         $tax_enabled = Configuration::get('PS_TAX');
     }
     if (!$tax_enabled) {
         return new TaxCalculator(array());
     }
     $taxes = array();
     $postcode = 0;
     if (!empty($this->address->postcode)) {
         $postcode = $this->address->postcode;
     }
     $context = Context::getContext();
     $cache_id = (int) $this->address->id_country . '-' . (int) $this->address->id_state . '-' . $postcode . '-' . (int) $this->type;
     if (!Cache::isStored($cache_id)) {
         $rows = Db::getInstance()->executeS('
             SELECT tr.*
             FROM `' . _DB_PREFIX_ . 'tax_rule` tr
             JOIN `' . _DB_PREFIX_ . 'tax_rules_group` trg ON (tr.`id_tax_rules_group` = trg.`id_tax_rules_group`)
             WHERE trg.`active` = 1
             AND tr.`id_country` = ' . (int) $this->address->id_country . '
             AND tr.`id_tax_rules_group` = ' . (int) $this->type . '
             AND tr.`id_state` IN (0, ' . (int) $this->address->id_state . ')
             AND (tr.`id_group` = ' . (int) Customer::getDefaultGroupId((int) $context->customer->id) . ' OR tr.`id_group` = 0)
             AND (\'' . pSQL($postcode) . '\' BETWEEN tr.`zipcode_from` AND tr.`zipcode_to` OR (tr.`zipcode_to` = 0 AND tr.`zipcode_from` IN(0, \'' . pSQL($postcode) . '\')))
             ORDER BY tr.`zipcode_from` DESC, tr.`zipcode_to` DESC, tr.`id_state` DESC, tr.`id_country` DESC');
         $behavior = 0;
         $first_row = true;
         foreach ($rows as $row) {
             $tax = new Tax((int) $row['id_tax']);
             $taxes[] = $tax;
             // the applied behavior correspond to the most specific rules
             if ($first_row) {
                 $behavior = $row['behavior'];
                 $first_row = false;
             }
             if ($row['behavior'] == 0) {
                 break;
             }
         }
         Cache::store($cache_id, new TaxCalculator($taxes, $behavior));
     }
     return Cache::retrieve($cache_id);
 }
コード例 #19
0
ファイル: rss.php プロジェクト: nbey/Emergence-Skeleton
function Dwoo_Plugin_rss(Dwoo_Core $dwoo, $feed, $assign = 'rss_items', $limit = 5, $cacheTime = 60)
{
    $cacheKey = 'rss:' . $feed;
    if (false === ($rss = Cache::fetch($cacheKey))) {
        $rss = new RssReader();
        $rss->load($feed);
        Cache::store($cacheKey, $rss, $cacheTime);
    }
    if ($limit) {
        $dwoo->assignInScope(array_slice($rss->getItems(), 0, $limit), $assign);
    } else {
        $dwoo->assignInScope($rss->getItems(), $assign);
    }
    return '';
}
コード例 #20
0
 public function setLastVisitedCategory()
 {
     $cache_id = 'pspagebuilder::setLastVisitedCategory';
     $context = Context::getContext();
     if (!Cache::isStored($cache_id)) {
         if (method_exists($context->controller, 'getCategory') && ($category = $context->controller->getCategory())) {
             $context->cookie->last_visited_category = $category->id;
         } elseif (method_exists($context->controller, 'getProduct') && ($product = $context->controller->getProduct())) {
             if (!isset($context->cookie->last_visited_category) || !Product::idIsOnCategoryId($product->id, array(array('id_category' => $context->cookie->last_visited_category))) || !Category::inShopStatic($context->cookie->last_visited_category, $context->shop)) {
                 $context->cookie->last_visited_category = (int) $product->id_category_default;
             }
         }
         Cache::store($cache_id, $context->cookie->last_visited_category);
     }
     return Cache::retrieve($cache_id);
 }
コード例 #21
0
ファイル: State.php プロジェクト: jpodracky/dogs
    /**
     * Get a state id with its name
     *
     * @param string $id_state Country ID
     * @return int state id
     */
    public static function getIdByName($state)
    {
        if (empty($state)) {
            return false;
        }
        $cache_id = 'State::getIdByName_' . pSQL($state);
        if (!Cache::isStored($cache_id)) {
            $result = (int) Db::getInstance()->getValue('
				SELECT `id_state`
				FROM `' . _DB_PREFIX_ . 'state`
				WHERE `name` = \'' . pSQL($state) . '\'
			');
            Cache::store($cache_id, $result);
            return $result;
        }
        return Cache::retrieve($cache_id);
    }
コード例 #22
0
 public static function getSourceCode($minifier, $cacheHashOrSourceReport, $skipCache = false)
 {
     $cacheHash = is_string($cacheHashOrSourceReport) ? $cacheHashOrSourceReport : $cacheHashOrSourceReport['hash'];
     $cacheKey = "{$minifier}:{$cacheHash}";
     if (!$skipCache && ($code = Cache::fetch($cacheKey))) {
         return $code;
     }
     if (is_array($cacheHashOrSourceReport) && is_array($cacheHashOrSourceReport['files'])) {
         $code = '';
         foreach ($cacheHashOrSourceReport['files'] as $path => $fileData) {
             $code .= $minifier::minify(file_get_contents(SiteFile::getRealPathByID($fileData['ID'])));
         }
         Cache::store($cacheKey, $code);
         return $code;
     }
     return null;
 }
コード例 #23
0
 public static function index()
 {
     $url = $_SERVER['REQUEST_URI'];
     $stripped_url = preg_replace("/[^A-Za-z0-9 ]/", '', $url);
     // Fetch page from cache
     $cached_page = Cache::getPage($stripped_url);
     if ($cached_page != null && Cache::on()) {
         // Use cached page (which is up to date because outdated pages are deleted)
         echo $cached_page;
     } else {
         // Make page from scratch
         $player = Player::find($_GET['player']);
         $game_count = Game::count_all_player_games($player->playerid);
         $latest_game = Game::latest_player_game($player->playerid);
         $high_scores = Game::player_high_scores($player->playerid);
         $years = Game::game_years();
         $popular_courses = Course::popular_courses($player->playerid);
         $throw_count = Score::count_all_player_scores($player->playerid);
         $birdies = Score::players_birdies($player->playerid);
         $aces = Score::players_aces($player->playerid);
         $courses_avg_scores = array();
         $names_done = false;
         foreach ($years as $year) {
             $avg_scores_by_year = Course::average_player_scoring_by_year($player->playerid, $year);
             for ($i = 0; $i < count($avg_scores_by_year); $i++) {
                 if (!$names_done) {
                     $averages = array();
                     $averages[] = $avg_scores_by_year[$i]['name'];
                     $courses_avg_scores[] = $averages;
                 }
                 if ($avg_scores_by_year[$i]['avg_score'] != null) {
                     $courses_avg_scores[$i][] = $avg_scores_by_year[$i]['avg_score'] . " (" . str_replace(" ", "", $avg_scores_by_year[$i]['to_par']) . ")";
                 } else {
                     $courses_avg_scores[$i][] = "";
                 }
             }
             $names_done = true;
         }
         $page_html = View::make('player/index.html', array('player' => $player, 'players' => Player::all(), 'game_count' => $game_count, 'throw_count' => $throw_count, 'latest_game' => $latest_game, 'high_scores' => $high_scores, 'popular_courses' => $popular_courses, 'birdies' => $birdies, 'aces' => $aces, 'years' => $years, 'courses_avg_scores' => $courses_avg_scores));
         if (Cache::on()) {
             Cache::store($stripped_url, $page_html);
         }
     }
 }
コード例 #24
0
ファイル: index.php プロジェクト: fear-otaku/oc-listcloud
function listcloud_CloudDump()
{
    require_once LIB_PATH . 'osclass/classes/Cache.php';
    $cache = new Cache('listcloud_feeds', 900);
    if ($cache->check()) {
        return $cache->retrieve();
    } else {
        $list = array();
        $content = osc_file_get_contents(osc_base_url() . 'index.php?page=search&sFeed=rss');
        if ($content) {
            $xml = simplexml_load_string($content);
            foreach ($xml->channel->item as $item) {
                $list[] = array('title' => strval($item->title));
            }
        }
        $cache->store($list);
    }
    return $list;
}
コード例 #25
0
ファイル: feeds.php プロジェクト: acharei/OSClass
/**
 * This functions retrieves a news list from http://osclass.org. It uses the Cache services to speed up the process.
 */
function osc_listNews()
{
    require_once LIB_PATH . 'osclass/classes/Cache.php';
    $cache = new Cache('admin-blog_news', 900);
    if ($cache->check()) {
        return $cache->retrieve();
    } else {
        $list = array();
        $content = osc_file_get_contents('http://osclass.org/feed/');
        if ($content) {
            $xml = simplexml_load_string($content);
            foreach ($xml->channel->item as $item) {
                $list[] = array('link' => strval($item->link), 'title' => strval($item->title), 'pubDate' => strval($item->pubDate));
            }
        }
        $cache->store($list);
    }
    return $list;
}
コード例 #26
0
ファイル: sqldb.php プロジェクト: seyyah/f3kulmysql
 /**
 		Retrieve from cache; or save SQL query results to cache if not
 		previously executed
 			@param $_cmd string
 			@param $_bind mixed
 			@param $_id string
 			@param $_ttl integer
 			@private
 	**/
 private static function sqlCache($_cmd, $_bind = NULL, $_id = 'DB', $_ttl = 0)
 {
     $_hash = 'sql.' . F3::hashCode($_cmd);
     $_db =& F3::$global[$_id];
     $_cached = Cache::cached($_hash);
     if ($_cached && time() - $_cached['time'] < $_ttl) {
         // Gather cached SQL queries for profiler
         F3::$global['PROFILE'][$_id]['cache'][$_cmd]++;
         // Retrieve from cache, unserialize, and restore DB variable
         $_db = unserialize(gzinflate(Cache::fetch($_hash)));
     } else {
         self::sqlExec($_cmd, NULL, $_id);
         if (!F3::$global['ERROR']) {
             // Serialize, compress and cache
             unset($_db['pdo'], $_db['query']);
             Cache::store($_hash, gzdeflate(serialize($_db)));
         }
     }
 }
コード例 #27
0
ファイル: sqldb.php プロジェクト: seyyah/f3kayOLD
 /**
 		Retrieve from cache; or save SQL query results to cache if not
 		previously executed
 			@param $_cmd string
 			@param $_bind mixed
 			@param $_id string
 			@param $_ttl integer
 			@private
 	**/
 private static function sqlCache($_cmd, $_bind = NULL, $_id = 'DB', $_ttl = 0)
 {
     $_hash = 'sql.' . F3::hashCode($_cmd);
     $_db =& F3::$global[$_id];
     $_cached = Cache::cached($_hash);
     if ($_cached && time() - $_cached['time'] < $_ttl) {
         // Gather cached SQL queries for profiler
         F3::$global['PROFILE'][$_id]['cache'][$_cmd]++;
         // Retrieve from cache
         $_db = Cache::fetch($_hash);
     } else {
         self::sqlExec($_cmd, NULL, $_id);
         if (!F3::$global['ERROR']) {
             // Save to cache
             unset($_db['pdo'], $_db['query']);
             Cache::store($_hash, $_db);
         }
     }
 }
コード例 #28
0
 public static function getFeedData($url, $cacheKey = false, $cacheTime = null)
 {
     if ($cacheTime === null) {
         $cacheTime = static::$defaultCacheTime;
     }
     // get context
     if (!isset(static::$_streamContext)) {
         static::$_streamContext = stream_context_create(array('http' => array('timeout' => static::$requestTimeout)));
     }
     $failureKey = 'fail:' . $cacheKey;
     if (!($twitterData = Cache::fetch($cacheKey)) && !Cache::fetch($failureKey)) {
         $twitterData = @json_decode(@file_get_contents($url, false, static::$_streamContext), true);
         if (empty($twitterData)) {
             Cache::store($failureKey, true, static::$failureDelay);
         }
         Cache::store($cacheKey, $twitterData, $cacheTime);
     }
     return $twitterData ? $twitterData : false;
 }
コード例 #29
0
function weather($code)
{
    $code = str_replace('-', ' ', $code);
    $code = urlencode($code);
    $cache = new Cache();
    $cache_name = 'weather_' . $code;
    $xml = '';
    $use_errors = libxml_use_internal_errors(true);
    if (!($xml = simplexml_load_string($cache->fetch($cache_name)))) {
        $result = @file_get_contents('http://api.openweathermap.org/data/2.5/forecast/daily?q=' . $code . ',uk&mode=xml&units=metric&cnt=7');
        if (!$result) {
            return false;
        }
        $cache->store($cache_name, $result, 86000);
        $xml = simplexml_load_string($result);
    }
    libxml_clear_errors();
    libxml_use_internal_errors($use_errors);
    return $xml;
}
コード例 #30
0
ファイル: Customer.php プロジェクト: ac3gam3r/Maxokraft
    /**
     * Return customer addresses
     * Override method with default Prestashop Method, To don't show the Receiver address to Custommer/ Sender
     * @param integer $id_lang Language ID
     * @param bool $ship2myid_flag flag to show the address
     * @return array Addresses
     */
    public function getAddresses($id_lang, $ship2myid_flag = true)
    {
        $share_order = (bool) Context::getContext()->shop->getGroup()->share_order;
        $cache_id = 'Customer::getAddresses' . (int) $this->id . '-' . (int) $id_lang . '-' . $share_order;
        if (!Cache::isStored($cache_id)) {
            $sql = 'SELECT DISTINCT a.*, cl.`name` AS country, s.name AS state, s.iso_code AS state_iso
					FROM `' . _DB_PREFIX_ . 'address` a
					LEFT JOIN `' . _DB_PREFIX_ . 'country` c ON (a.`id_country` = c.`id_country`)
					LEFT JOIN `' . _DB_PREFIX_ . 'country_lang` cl ON (c.`id_country` = cl.`id_country`)
					LEFT JOIN `' . _DB_PREFIX_ . 'state` s ON (s.`id_state` = a.`id_state`)
					' . ($share_order ? '' : Shop::addSqlAssociation('country', 'c')) . ' 
					WHERE `id_lang` = ' . (int) $id_lang . ' AND `id_customer` = ' . (int) $this->id . ' AND a.`deleted` = 0';
            //echo $ship2myid_flag.'hii';
            if ($ship2myid_flag) {
                $sql .= ' AND ( ( LOWER(alias ) NOT LIKE "ship2myid-%") AND (LOWER(alias) NOT LIKE "shiptomyid-%" ) ) ';
            }
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
            Cache::store($cache_id, $result);
        }
        return Cache::retrieve($cache_id);
    }