本文整理汇总了PHP中cache_set函数的典型用法代码示例。如果您正苦于以下问题:PHP cache_set函数的具体用法?PHP cache_set怎么用?PHP cache_set使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cache_set函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: flickr_photos_get_by_id
function flickr_photos_get_by_id($id)
{
$cache_key = "photo_{$id}";
$cache = cache_get($cache_key);
if ($cache['ok']) {
return $cache['data'];
}
$lookup = flickr_photos_lookup_photo($id);
if (!$lookup) {
return;
}
$user = users_get_by_id($lookup['user_id']);
$cluster_id = $user['cluster_id'];
# Temporary – this should never happen
if (!$cluster_id) {
return null;
}
$enc_id = AddSlashes($id);
$sql = "SELECT * FROM FlickrPhotos WHERE id='{$enc_id}'";
$rsp = db_fetch_users($cluster_id, $sql);
$row = db_single($rsp);
if ($row) {
cache_set($cache_key, $row, "cache_locally");
}
return $row;
}
示例2: enplacify_yelp_get_listing
function enplacify_yelp_get_listing($listing_id)
{
$cache_key = "enplacify_yelp_listing_{$listing_id}";
$cache = cache_get($cache_key);
if ($cache['ok']) {
return $cache['data'];
}
$url = "http://www.yelp.com/biz/" . urlencode($listing_id);
$headers = array();
$more = array('follow_redirects' => 1);
$rsp = http_get($url, $headers, $more);
if (!$rsp['ok']) {
return $rsp;
}
$vcard_rsp = vcard_parse_html($rsp['body']);
$graph_rsp = opengraph_parse_html($rsp['body']);
if (!$vcard_rsp['ok'] && !$graph_rsp['ok']) {
$rsp = array('ok' => 0, 'error' => 'Failed to parse listing');
} else {
$listing = array_merge($vcard_rsp['vcard'], $graph_rsp['graph']);
$listing['id'] = $listing_id;
$rsp = array('ok' => 1, 'listing' => $listing);
}
cache_set($cache_key, $rsp);
return $rsp;
}
示例3: google_get_mymaps_kml_feed
function google_get_mymaps_kml_feed($url)
{
$cache_key = "mymaps_kml_" . md5($url);
$cache = cache_get($cache_key);
if ($cache['ok']) {
return $cache['data'];
}
$parts = utils_parse_url($url);
if (!google_is_mymaps_hostname($parts['host'])) {
return null;
}
if ($parts['path'] != '/maps/ms') {
return null;
}
$query = array();
foreach (explode("&", $parts['query']) as $q) {
list($key, $value) = explode("=", $q, 2);
$query[$key] = $value;
}
if (!$query['msid']) {
return null;
}
$query['output'] = 'kml';
$feed_url = "http://{$parts['host']}{$parts['path']}?" . http_build_query($query);
#
cache_set($cache_key, $feed_url, "cache locally");
return $feed_url;
}
示例4: setValue
/**
* Set config option value
*
* @param string $name
* @param mixed $value
* @return mixed
*/
function setValue($name, $value)
{
$option = ConfigOptions::findByName($name);
if (instance_of($option, 'ConfigOption')) {
$option->setValue($value);
$save = $option->save();
if ($save && !is_error($save)) {
$cached_values = cache_get('config_values');
if (is_array($cached_values)) {
$cached_values[$name] = $value;
} else {
$cached_values = array($name => $value);
}
// if
cache_set('config_values', $cached_values);
cache_remove(TABLE_PREFIX . 'config_options_name_' . $name);
return $value;
} else {
return $save;
}
// if
} else {
return new InvalidParamError('name', $name, "System configuration option '{$name}' does not exist", true);
}
// if
}
示例5: enplacify_chowhound_get_restaurant
function enplacify_chowhound_get_restaurant($restaurant_id)
{
$cache_key = "enplacify_chowhound_restaurant_{$restaurant_id}";
$cache = cache_get($cache_key);
if ($cache['ok']) {
return $cache['data'];
}
$url = "http://www.chow.com/restaurants/" . urlencode($restaurant_id);
$headers = array();
$more = array('follow_redirects' => 1);
$rsp = http_get($url, $headers, $more);
if (!$rsp['ok']) {
return $rsp;
}
$vcard_rsp = vcard_parse_html($rsp['body']);
$graph_rsp = opengraph_parse_html($rsp['body']);
if (!$vcard_rsp['ok'] && !$graph_rsp['ok']) {
$rsp = array('ok' => 0, 'error' => 'Failed to parse restaurant');
} else {
$restaurant = array_merge($vcard_rsp['vcard'], $graph_rsp['graph']);
$restaurant['id'] = $restaurant_id;
$rsp = array('ok' => 1, 'restaurant' => $restaurant);
}
cache_set($cache_key, $rsp);
return $rsp;
}
示例6: __construct
/**
* Constructor
*
* @param $users
* Mandatory - An array of integers or single integer specifying the Drupal users to notify.
*
* @param $defaultMessage
* String: The default message to send in the email, overridden with the message stored in the template_data record
*
* @param $defaultSubject
* String: The default email subject, overridden with the message stored in the template_data record
*
* @param $queueID
* Integer: The QueueID associated with the message you're sending out
*
* @param $type
* String: The actual notification type using the MaestroNotificationTypes Constants
*/
function __construct($defaultMessage = '', $defaultSubject = '', $queueID = 0, $type = MaestroNotificationTypes::ASSIGNMENT)
{
$observers = array();
$this->_notificationType = $type;
$this->_queueID = $queueID;
$this->getNotificationUserIDs();
$this->setNotificationSubjectAndMessage($defaultMessage, $defaultSubject);
//Now, lets determine if we've got our observers cached. If not, lets rebuild that observer list
//This is how we subscribe to becoming a notification provider for Maestro.
$observers = cache_get('maestro_notification_observers');
if ($observers === FALSE) {
//build the observer cache
//need to scan through each available class type and fetch its corresponding context menu.
foreach (module_implements('maestro_notification_observer') as $module) {
$function = $module . '_maestro_notification_observer';
if ($declaredObserver = $function()) {
foreach ($declaredObserver as $observerToCache) {
$observers[] = $observerToCache;
$this->_observers[] = $observerToCache;
}
}
}
cache_set('maestro_notification_observers', $observers);
} else {
$this->_observers = $observers->data;
}
}
示例7: init_registry
/**
* Returns an associative array of classes known to extend Node.
* Pulls this array from cache if available - if not, generates
* and caches it.
*
* Class names are keyed on their machine name.
*
* @access private
* @static
* @return array
*/
private static function init_registry()
{
$cache = cache_get(self::DOODAL_CACHE_ID);
##
## Attempt to get registry from cache
if ($cache && !empty($cache->data)) {
return $cache->data;
} else {
##
## Load all classes registered for autoloading not in an ignored (i.e. system) module
$results = db_query("SELECT name FROM {registry} WHERE type = 'class' AND module != '' AND module NOT IN (:modules) ORDER BY name", array(':modules' => self::get_ignored_modules()))->fetchAll();
##
## Get subset of classes marked as "node"
$registry = array();
foreach ($results as $result) {
$reflectedClass = new ReflectionAnnotatedClass($result->name);
if ($reflectedClass->hasAnnotation('MachineName')) {
$registry[$reflectedClass->getAnnotation('MachineName')->value] = $result->name;
}
}
##
## Cache results and return
cache_set(self::DOODAL_CACHE_ID, $registry, 'cache', CACHE_PERMANENT);
return $registry;
}
}
示例8: make_captcha
function make_captcha($id)
{
require 'kcaptcha/kcaptcha.php';
$captcha = new KCAPTCHA();
cache_set('taxi_captcha_' . $id, $captcha->getKeyString());
die;
}
示例9: sheets_lookup_by_fingerprint
function sheets_lookup_by_fingerprint($fingerprint, $user_id = 0)
{
$cache_key = "sheets_lookup_fingerprint_{$fingerprint}";
$cache = cache_get($cache_key);
if ($cache['ok']) {
return $cache['data'];
}
#
$enc_fingerprint = AddSlashes($fingerprint);
$sql = "SELECT * FROM SheetsLookup WHERE fingerprint='{$enc_fingerprint}'";
if ($user_id) {
$enc_id = AddSlashes($user_id);
$sql .= " AND user_id='{$enc_id}'";
}
$rsp = db_fetch($sql);
$sheets = array();
foreach ($rsp['rows'] as $row) {
$more = array('sheet_user_id' => $row['user_id']);
if ($sheet = sheets_get_sheet($row['sheet_id'], $user_id, $more)) {
$sheets[] = $sheet;
}
}
cache_set($cache_key, $sheets);
return $sheets;
}
示例10: cachedRequest
public static function cachedRequest($url, array $options = array(), $cache_errors = FALSE)
{
$cid = static::cachedRequestGetCid($url, $options);
$bin = isset($options['cache']['bin']) ? $options['cache']['bin'] : 'cache';
if ($cid && ($cache = CacheHelper::get($cid, $bin))) {
return $cache->data;
} else {
$response = drupal_http_request($url, $options);
$response->request_url = $url;
$response->request_options = $options;
if (!empty($response->error)) {
trigger_error("Error on request to {$url}: {$response->code} {$response->error}.", E_USER_WARNING);
}
if (!$cache_errors && !empty($response->error)) {
$cid = FALSE;
}
if ($cid) {
$expire = static::cachedRequestGetExpire($response, $options);
if ($expire !== FALSE) {
cache_set($cid, $response, $bin, $expire);
}
}
return $response;
}
}
示例11: findAssigneesByObject
/**
* Return all users assigned to a specific object
*
* @param ProjectObject $object
* @return array
*/
function findAssigneesByObject($object)
{
$cache_id = 'object_assignments_' . $object->getId();
$cached_values = cache_get($cache_id);
if (is_array($cached_values)) {
if (count($cached_values) > 0) {
return Users::findByIds($cached_values);
} else {
return null;
}
// if
}
// if
$users_table = TABLE_PREFIX . 'users';
$assignments_table = TABLE_PREFIX . 'assignments';
$cached_values = array();
$rows = db_execute_all("SELECT {$users_table}.id FROM {$users_table}, {$assignments_table} WHERE {$assignments_table}.object_id = ? AND {$assignments_table}.user_id = {$users_table}.id", $object->getId());
if (is_foreachable($rows)) {
foreach ($rows as $row) {
$cached_values[] = (int) $row['id'];
}
// foreach
}
// if
cache_set($cache_id, $cached_values);
if (count($cached_values) > 0) {
return Users::findByIds($cached_values);
} else {
return null;
}
// if
}
示例12: flickr_photos_metadata_load
function flickr_photos_metadata_load(&$photo)
{
$cache_key = "photos_meta_{$photo['id']}";
$cache = cache_get($cache_key);
if ($cache['ok']) {
return $cache['data'];
}
$meta = flickr_photos_metadata_path($photo);
if (!file_exists($meta)) {
return array('ok' => 0, 'error' => 'missing meta file');
}
$fh = fopen($meta, "r");
$data = fread($fh, filesize($meta));
fclose($fh);
$data = json_decode($data, "as hash");
# guh... just in case stuff has been double
# json encoded; this was a by-product of moving
# over to the http_multi stuff and not realizing
# what I was doing (20111114/straup)
if ($data && !is_array($data)) {
$data = json_decode($data, "as hash");
}
if (!$data) {
return array('ok' => 0, 'error' => 'failed to decode');
}
$rsp = array('ok' => 1, 'data' => $data);
cache_set($cache_key, $rsp);
return $rsp;
}
示例13: getValue
/**
* Return value of $name config option for a given project
*
* @param string $name
* @param Project $project
* @return mixed
*/
function getValue($name, $project)
{
$cache_id = 'project_config_options_' . $project->getId();
$cached_value = cache_get($cache_id);
if (is_array($cached_value) && isset($cached_value[$name])) {
return $cached_value[$name];
}
// if
$option = ConfigOptions::findByName($name, PROJECT_CONFIG_OPTION);
if (instance_of($option, 'ConfigOption')) {
$record = db_execute_one('SELECT value FROM ' . TABLE_PREFIX . 'project_config_options WHERE project_id = ? AND name = ?', $project->getId(), $name);
if (is_array($record) && isset($record['value'])) {
$value = trim($record['value']) != '' ? unserialize($record['value']) : null;
} else {
$value = $option->getValue();
}
// if
if (is_array($cached_value)) {
$cached_value[$name] = $value;
} else {
$cached_value = array($name => $value);
}
// if
cache_set($cache_id, $cached_value);
return $value;
} else {
return new InvalidParamError('name', $name, "Project configuration option '{$name}' does not exist", true);
}
// if
}
示例14: __construct
function __construct($template_id)
{
$this->_template_id = $template_id;
$context_options = cache_get('maestro_taskclass_info');
// Test if context options are cached - if not then we will set it
// The class function getContextMenu will read options from the cache
if ($context_options === FALSE) {
$context_options = array();
// Scan through each available class type and fetch its corresponding context menu.
foreach (module_implements('maestro_get_taskobject_info') as $module) {
$function = $module . '_maestro_get_taskobject_info';
if ($arr = $function()) {
$context_options = maestro_array_add($context_options, $arr);
}
}
cache_set('maestro_taskclass_info', $context_options);
}
$handler_options = cache_get('maestro_handler_options');
// Test if task type handler options are cached - if not then we will set it
// The class function getHandlerOptions will read options from the cache
if ($handler_options === FALSE) {
// Scan through each available class type and fetch its corresponding context menu.
foreach (module_implements('maestro_handler_options') as $module) {
$function = $module . '_maestro_handler_options';
if ($arr = $function()) {
$handler_options = maestro_array_merge_keys($arr, $handler_options);
}
}
cache_set('maestro_handler_options', $handler_options);
}
}
示例15: enplacify_flickr_get_photo
function enplacify_flickr_get_photo($photo_id)
{
if (!$GLOBALS['cfg']['flickr_apikey']) {
return array('ok' => 0, 'error' => 'No Flickr API key');
}
$cache_key = "enplacify_flickr_photo_{$photo_id}";
$cache = cache_get($cache_key);
if ($cache['ok']) {
return $cache['data'];
}
$url = "http://api.flickr.com/services/rest/?method=flickr.photos.getInfo";
$url .= "&photo_id={$photo_id}";
$url .= "&api_key={$GLOBALS['cfg']['flickr_apikey']}";
$url .= "&format=json&nojsoncallback=1";
$rsp = http_get($url);
if (!$rsp['ok']) {
return $rsp;
}
$json = json_decode($rsp['body'], "fuck off php");
if ($json['stat'] != 'ok') {
return array('ok' => 0, 'error' => 'Flickr API error');
}
$photo = $json['photo'];
$rsp = array('ok' => 1, 'photo' => $json['photo']);
cache_set($cache_key, $rsp);
return $rsp;
}