voceconnect / no-stampede-actions
A WordPress api to kick off globally singleton actions. It will lock the action to prevent other requests from kicking off the same action.
Installs: 1 268
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 15
Forks: 3
Open Issues: 0
This package is auto-updated.
Last update: 2024-11-29 04:19:49 UTC
README
Please note: This plugin is no longer being actively maintained or supported.
No Stampede Actions
Contributors: prettyboymp, kevinlangleyjr, csloisel
Tags: performance, caching
Requires at least: 3.0
Tested up to: 3.7.1
Stable tag: 1.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Description
A WordPress api to kick off globally singleton actions. It will lock the action to prevent other requests from kicking off the same action
Installation
As theme or plugin dependency:
After dropping the plugin into the containing theme or plugin, add the following:
<?php if( ! class_exists( 'NSA_Action' ) ) { require_once( $path_to_nsa_actions . '/no-stampede-actions.php' ); }
Usage
<?php function long_request(){ $val = wp_cache_get( 'long_request_key' ); if( $val === false ){ nsa_action('long_request') ->action_callback( 'long_request_callback', array( 'http://example.com/long-running-request.php' ) ) ->background_only( false ) ->max_tries( 10 ) ->do_action( ); $val = wp_cache_get( 'long_request_key' ); } return $val; } function long_request_callback($url){ $content = wp_remote_retrieve_body( wp_remote_get( $url, array( 'timeout' => 30 ) ) ); wp_cache_set( 'long_request_key', $content ); return $content; }