Stash
Stash copied to clipboard
Call to protected method Stash\Driver\FileSystem::setOptions
From my interpretation of the README, BASICS, and DRIVER documentation, I believe this the easiest way to get a hello world implementation that actually caches to disk:
<?php
require 'vendor/autoload.php';
// Uses a install specific default path if none is passed.
$driver = new Stash\Driver\FileSystem();
// Setting a custom path is done by passing an options array to the constructor.
$options = array('path' => 'cache/');
$driver->setOptions($options);
// Get a cache item.
$item = $pool->getItem('path/to/item');
// Attempt to get the data
$data = $item->get();
// Check to see if the data was a miss.
if($item->isMiss())
{
// Let other processes know that this one is rebuilding the data.
$item->lock();
// Run intensive code
$data = "hello";
// Store the expensive to generate data.
$pool->save($item->set($data));
}
// Continue as normal.
var_dump($data);
This produces the error
Fatal error: Call to protected method Stash\Driver\FileSystem::setOptions() from context '' in /home/phor/public_html/apps/linkbuilding-spider/run-report.php on line 9
setOptions has been moved to the driver constructor.
Including the autoloader will load Stash, but you are responsible for loading the PSR-6 Caching interfaces if you aren't using composer. The by-far-easiest method is to use composer and include it's autoloader.
I ran into this too, I guess the docs need updated http://www.stashphp.com/Drivers.html ?
<?php
// Uses a install specific default path if none is passed.
$driver = new Stash\Driver\FileSystem();
// Setting a custom path is done by passing an options array to the constructor.
$options = array('path' => '/tmp/myCache/');
$driver->setOptions($options);
Same here for the Memcache driver. A doc update would clearify things.
How should I update my example to work?
Just pass the options array when you instantiate the driver. I checked the master at tedious/www.stashphp.com and it currently shows the example below, so fixed documentation is in the works.
<?php
// Setting a custom path is done by passing an options array to the constructor.
$options = array('path' => '/tmp/myCache/');
// Uses a install specific default path if none is passed.
$driver = new Stash\Driver\FileSystem($options);
I ran into the same issue, the documentation is advising using setOptions
.
To be clear, are you still accepting contributions to this project? If so would a PR that fixes this documentation issue be in scope to be merged?
If someone wants to fix the docs I'll happily merge it.