WordPress drop in used to help prevent stampeding for actions that should only run once.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.mdown
composer.json
no-stampede-actions.php

README.mdown

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;
}