matthiasmullie / scrapbook

PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APC(u), SQL and additional capabilities (e.g. transactions, stampede protection) built on top.
https://www.scrapbook.cash
MIT License
315 stars 27 forks source link

undefined method: collection #52

Closed zlo2k closed 1 year ago

zlo2k commented 3 years ago

Hi! I am trying to run a simple example and I get the error:

Fatal error: Uncaught Error: Call to undefined method MatthiasMullie\Scrapbook\Adapters\Memcached::collection() in test.php:8 Stack trace: #0 {main} thrown in test.php on line 8

Apache 2.4, PHP 7.2, Memcached server 1.5, PHPINFO Memcached section: Version | 3.1.4 libmemcached version | 1.0.18

<?php
require_once 'vendor/autoload.php';

$client = new \Memcached();
$client->addServer('localhost', 11211);
$cache = new \MatthiasMullie\Scrapbook\Adapters\Memcached($client);

$articleCache = $cache->collection('articles');
$sessionCache = $cache->collection('sessions');

$cache->set('key', 'value one');
$articleCache->set('key', 'value two');
$sessionCache->set('key', 'value three');

$articleCache->flush();

$cache->flush();

Maybe I was wrong about something?

matthiasmullie commented 1 year ago

The method to call is ->getCollection() rather than ->collection().