public function init() { if (isset($_POST['_tlc_update']) && 0 === strpos($_POST['_tlc_update'], 'tlc_lock_') && isset($_POST['key'])) { $update = get_transient('tlc_up__' . md5($_POST['key'])); if ($update && $update[0] == $_POST['_tlc_update']) { tlc_transient($update[1])->expires_in($update[2])->extend_on_fail($update[5])->updates_with($update[3], (array) $update[4])->set_lock($update[0])->fetch_and_cache(); } exit; } }
public function init() { if (isset($_POST['_tlc_update'])) { $update = get_transient('tlc_up__' . $_POST['key']); if ($update && $update[0] == $_POST['_tlc_update']) { tlc_transient($update[1])->expires_in($update[2])->updates_with($update[3], (array) $update[4])->set_lock($update[0])->fetch_and_cache(); } exit; } }
function vpt_get_cached_query($query_args, $expires_in = 180, $transient_key = false) { if (!$transient_key) { $transient_key = 'vpt_query_' . substr(md5(serialize(func_get_args())), 0, 25); } $query = tlc_transient($transient_key)->updates_with('vpt_get_wp_query', array($query_args))->expires_in($expires_in)->get(); if (!is_a($query, 'WP_Query')) { return new WP_Query($query_args); } return $query; }
/** * @param array $args * @param array $instance */ public function widget($args, $instance) { $content = tlc_transient('popular-authors-widget')->updates_with([$this, 'get_widget_content'])->expires_in(2 * HOUR_IN_SECONDS)->get(); if (empty($content)) { return; } /** This filter is documented in wp-includes/default-widgets.php */ $title = apply_filters('widget_title', empty($instance['title']) ? __('Popular Posts') : $instance['title'], $instance, $this->id_base); echo $args['before_widget']; if ($title) { echo $args['before_title'] . $title . $args['after_title']; } echo $content; echo $args['after_widget']; }
/** * Run the API query or get from cache * * @uses 'rest_pre_dispatch' filter * @param null $result * * @param obj| WP_JSON_Server $server * @param obj| WP_REST_Request $request * @since 0.1.0 */ function jp_rest_cache_get($result, $server, $request) { if (!function_exists('jp_rest_cache_rebuild')) { return $result; } /** * Cache override. * * @since 0.1.0 * * @param bool $no_cache If true, cache is skipped. If false, there will be caching. * @param string $endpoint The endpoint for the current request. * @param string $method The HTTP method being used to make current request. * * @return bool */ $endpoint = $request->get_route(); $method = $request->get_method(); $request_uri = $_SERVER['REQUEST_URI']; $skip_cache = apply_filters('jp_rest_cache_skip_cache', false, $endpoint, $method); if ($skip_cache) { return $result; } if ($request->get_param('refresh-cache') === true) { return $result; } /** * Set cache time * * @since 0.1.0 * * @param int $cache_time Time in seconds to cache for. Defaults to value of JP_REST_CACHE_DEFAULT_CACHE_TIME. * @param string $endpoint The endpoint for the current request. * @param string $method The HTTP method being used to make current request. * * @return bool */ $cache_time = apply_filters('jp_rest_cache_skip_cache', JP_REST_CACHE_DEFAULT_CACHE_TIME, $endpoint, $method); $result = tlc_transient(__FUNCTION__ . $request_uri)->updates_with('jp_rest_cache_rebuild', array($server, $request))->expires_in($cache_time)->get(); return $result; }
/** * Wrapper to retrieve data through TLC Transient. * * @param string $name * @param array $args * @param mixed $salt * * @return mixed */ public function fetch($name, $args, $salt = '') { global $current_user; static $empty_user; if (self::$in_callback || apply_filters('fc_skip_cache', false, $this->type, $name, $args, $salt)) { return $this->callback($name, $args); } // anonymize front-end run for consistency if (is_user_logged_in()) { if (empty($empty_user)) { $empty_user = new \WP_User(0); } $stored_user = $current_user; $current_user = $empty_user; } $salt = maybe_serialize($salt); $output = tlc_transient('fragment-cache-' . $this->type . '-' . $name . $salt)->updates_with(array($this, 'wrap_callback'), array($name, $args))->expires_in($this->timeout)->get(); if (!empty($stored_user)) { $current_user = $stored_user; } return $output; }
/** * Gets tweets, from cache if possible * * @param array $widgetOptions - options needed to get feeds * @return array - Array of objects */ private function _getTweets($widgetOptions) { $key = 'twp_' . md5(maybe_serialize($this->_get_feed_request_settings($widgetOptions))); return tlc_transient($key)->expires_in(300)->extend_on_fail(120)->updates_with(array($this, 'parseFeed'), array($widgetOptions))->get(); }
/** * Gets tweets, from cache if possible * * @param array $widgetOptions - options needed to get feeds * @return array - Array of objects */ private function _getTweets($widgetOptions) { $key = 'twp_' . md5($this->_getFeedUrl($widgetOptions)); return tlc_transient($key)->expires_in(300)->updates_with(array($this, 'parseFeed'), array($widgetOptions))->get(); }
/** * Find the posts with geolocation meta nearest to the given post. * Results are pulled from the cache if possible. * * @param int $post_id The post to search around * @param int $count Maximum number of results to return * * @return array Post IDs of the nearest posts */ function wctampa2015_get_nearby_posts_cached($post_id = 0, $count = 3) { if (!$post_id) { $post_id = get_the_ID(); } return tlc_transient('nearby_posts_' . $post_id . '_' . $count)->updates_with('wctampa2015_get_nearby_posts_v2', [$post_id, $count])->expires_in(12 * HOUR_IN_SECONDS)->get(); }
function twitter_feed($user, $count) { $transient_name = 'twitter_feed_' . $user . '_' . $count; return tlc_transient($transient_name)->updates_with('twitter_feed_get', array($user, $count))->expires_in(900)->background_only()->get(); }
/** * Wrapper function to clear cache that relates to related orders * * @param null $id */ public function wcs_clear_related_order_cache($id = null) { // if nothing was passed in, there's nothing to delete if (null === $id) { return; } // if it's not a Subscription, we don't deal with it if (is_object($id) && $id instanceof WC_Subscription) { $id = $id->id; } elseif (is_numeric($id)) { $id = absint($id); } else { return; } $key = tlc_transient('wcs-related-orders-to-' . $id)->key; $this->log('In the clearing, key being purged is this: ' . "\n\n{$key}\n\n"); $this->delete_cached($key); }
private function updateClicks() { if (is_multisite()) { tlc_transient('mtpc_client_clicks')->updates_with(array($this, 'updateClicksForMultiSite'), [get_current_blog_id()])->background_only()->expires_in(600)->get(); } else { tlc_transient('mtpc_clicks')->updates_with(array($this, 'updateClicksForSingleSite'))->background_only()->expires_in(600)->get(); } }
function meetup_recentwork_display() { $t = tlc_transient('meetup_recentwork_transient'); if (true) { $t->updates_with('meetup_recentwork'); } else { $t->updates_with('meetup_recentwork_backup'); } $t->expires_in(180); $t->background_only(); return $t->get(); }