Skip to content

Commit

Permalink
Update psr/cache requirment to include v2 and v3
Browse files Browse the repository at this point in the history
Also updates the cache implementation used in the example file
because tedvium/stash doesn't yet support the new versions of
psr/cacche.

Fix a bug with the cache example which was using the 'test'
API call, which declares itself as 'nocache'. Instead, call
it manually (with the default of nocache=false).

Refs #55
  • Loading branch information
samwilson authored Jan 18, 2023
1 parent 4744297 commit a25e40a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
"ext-libxml": "*",
"ext-simplexml": "*",
"carlos-mg89/oauth": "^0.8",
"psr/cache": "^1.0"
"psr/cache": "^1.0|^2.0|^3.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.0",
"mediawiki/minus-x": "^0.3 || ^1.0",
"phpunit/phpunit": "^9.5",
"tedivm/stash": "^0.17.1",
"symfony/cache": "^5.4",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phan/phan": "^5.4"
},
Expand Down
11 changes: 5 additions & 6 deletions examples/caching.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
// Make sure we have the required configuration values.
$configFile = __DIR__ . '/config.php';
require_once $configFile;
if (empty($apiKey) || empty($apiSecret) || empty($accessToken) || empty($accessTokenSecret)) {
echo 'Please set $apiKey, $apiSecret, $accessToken, and $accessTokenSecret in ' . $configFile;
if (empty($apiKey) || empty($apiSecret)) {
echo 'Please set $apiKey and $apiSecret in ' . $configFile;
exit(1);
}

Expand All @@ -22,9 +22,8 @@
sendRequests($flickr);

// Now add a cache.
$driver = new Stash\Driver\FileSystem([ 'path' => __DIR__ . '/cache' ]);
$pool = new Stash\Pool($driver);
$flickr->setCache($pool);
$cache = new Symfony\Component\Cache\Adapter\FilesystemAdapter('PhpFlickr', 0, __DIR__ . '/cache/');
$flickr->setCache($cache);

// Now send the same requests, and the second of them should be much faster.
echo "With caching:\n";
Expand All @@ -38,7 +37,7 @@ function sendRequests(\Samwilson\PhpFlickr\PhpFlickr $flickr)
{
for ($i = 1; $i <= 3; $i++) {
$start = microtime(true);
$flickr->test_echo([]);
$flickr->request('flickr.test.echo');
echo " $i. " . number_format(microtime(true) - $start, 3) . "\n";
}
}

0 comments on commit a25e40a

Please sign in to comment.