Stash icon indicating copy to clipboard operation
Stash copied to clipboard

Call to protected method Stash\Driver\FileSystem::setOptions

Open fulldecent opened this issue 8 years ago • 8 comments

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

fulldecent avatar Mar 17 '16 15:03 fulldecent

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.

tedivm avatar Mar 17 '16 17:03 tedivm

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

rschmitty avatar Jun 05 '16 14:06 rschmitty

Same here for the Memcache driver. A doc update would clearify things.

emielmolenaar avatar Jun 08 '16 08:06 emielmolenaar

How should I update my example to work?

fulldecent avatar Jun 24 '16 17:06 fulldecent

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

geekwright avatar Jun 24 '16 19:06 geekwright

I ran into the same issue, the documentation is advising using setOptions.

adaojunior avatar Sep 26 '16 18:09 adaojunior

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?

fulldecent avatar Feb 28 '18 02:02 fulldecent

If someone wants to fix the docs I'll happily merge it.

tedivm avatar Feb 28 '18 16:02 tedivm