Specifies that the resulting CFResponse object should be cached according to the settings from
set_cache_config().
Access
public
Parameters
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
|
Required |
The time the cache is to expire. Accepts a number of seconds as an integer, or an amount of time, as a string, that is understood by |
Returns
Type |
Description |
|---|---|
|
A reference to the current instance. |
Examples
Fire a single request, and then cache the response to APC.
Note: This method is inherited by all service-specific classes.
// Instantiate
$sdb = new AmazonSDB();
$sdb->set_cache_config('apc');
// First time pulls live data
$response = $sdb->cache(10)->list_domains();
var_dump($response->isOK());
// Second time pulls from cache
$response = $sdb->cache(10)->list_domains();
var_dump($response->isOK());
Result:
bool(true) bool(true)
Fire a single request, and then cache the response to the file system.
Note: This method is inherited by all service-specific classes.
// Instantiate
$sdb = new AmazonSDB();
$sdb->set_cache_config('./cache');
// First time pulls live data
$response = $sdb->cache(10)->list_domains();
var_dump($response->isOK());
// Second time pulls from cache
$response = $sdb->cache(10)->list_domains();
var_dump($response->isOK());
Result:
bool(true) bool(true)
Fire a single request, and then cache the response to Memcache.
Note: This method is inherited by all service-specific classes.
// Instantiate
$sdb = new AmazonSDB();
$sdb->set_cache_config(array(
array('host' => '127.0.0.1')
));
// First time pulls live data
$response = $sdb->cache(10)->list_domains();
var_dump($response->isOK());
// Second time pulls from cache
$response = $sdb->cache(10)->list_domains();
var_dump($response->isOK());
Result:
bool(true) bool(true)
Batch several requests together, and then cache the responses to APC.
Note: This method is inherited by all service-specific classes.
// Instantiate
$sdb = new AmazonSDB();
$sdb->set_cache_config('apc');
// Prepare for parallel requests
$sdb->batch()->list_domains();
$sdb->batch()->list_domains();
// First time pulls live data
$response = $sdb->batch()->cache('1 minute')->send(false);
var_dump($response[0]->isOK());
var_dump($response[1]->isOK());
// Second time pulls from cache
$response = $sdb->batch()->cache('1 minute')->send(false);
var_dump($response[0]->isOK());
var_dump($response[1]->isOK());
Result:
bool(true) bool(true) bool(true) bool(true)
Batch several requests together, and then cache the responses to the file system.
Note: This method is inherited by all service-specific classes.
// Instantiate
$sdb = new AmazonSDB();
$sdb->set_cache_config('./cache');
// Prepare for parallel requests
$sdb->batch()->list_domains();
$sdb->batch()->list_domains();
// First time pulls live data
$response = $sdb->batch()->cache('1 minute')->send(false);
var_dump($response[0]->isOK());
var_dump($response[1]->isOK());
// Second time pulls from cache
$response = $sdb->batch()->cache('1 minute')->send(false);
var_dump($response[0]->isOK());
var_dump($response[1]->isOK());
Result:
bool(true) bool(true) bool(true) bool(true)
Source
Method defined in sdk.class.php | Toggle source view (22 lines) | View on GitHub

