1. Go to this page and download the library: Download decodelabs/stash library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
decodelabs / stash example snippets
use DecodeLabs\Stash;
$stash = new Stash();
$myCache = $stash->load('MyCache');
if(!$myCache->has('myValue')) {
$myCache->set('myValue', [1, 2, 3]);
}
$total = 0;
foreach($myCache->get('myValue', []) as $number) {
$total += $number;
}
$myCache->delete('myValue');
$myValue = $myCache->fetch('myValue', function() {
return [1, 2, 3]; // Only called if key not found in cache
});
use DecodeLabs\Stash\DriverManager;
$stash = new Stash(new DriverManager(
new RedisConfig('localRedis'),
new RedisConfig('anotherRedis', host: '123.456.789.000', port: 6379),
new MemcacheConfig('remoteMemcache', host: '123.456.789.000', port: 11211),
new NamespaceConfig('MyStore', driver: 'remoteMemcache'),
new FileStoreConfig('specialFileStore', path: '/tmp/stash/fileStore'),
));
use DecodeLabs\Fabric\Kingdom as FabricKingdom;
use DecodeLabs\Kingdom\ContainerAdapter;
use DecodeLabs\Stash\DriverManager;
use DecodeLabs\Stash\DriverConfig\Redis as RedisConfig;
class Kingdom extends FabricKingdom
{
public function initialize(): void
{
parent::initialize();
$this->container->setFactory(
DriverManager::class,
fn () => new DriverManager(
new RedisConfig('localRedis')
)
);
}
}
namespace MyApp;
use DecodeLabs\Stash\Store;
use DecodeLabs\Stash\Store\Generic;
class MyCache extends Generic
{
public function getMyData(): string
{
return $this->fetch('myData', function() {
return 'Hello world';
});
}
}
$archetype->map(Store::class, namespace::class);
$myCache = $stash->load('MyCache'); // Will now use MyApp\MyCache
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.