Search code examples
phpphpfastcache

Setting memcached host/port in PHPFastCache


I'm currently able to use Memcached proper using the Memcached class. Setting the port for Memcached seems to work like this;

$mem = new memcached();

$mem->addServer("127.0.0.1", 3333);

The memcached class connects properly to the memcached server and is able to set/get.

For phpFastCache however, I can't seem to set the port number properly and its documentation doesn't offer a whole lot of examples. It does however seem to have a setting for hosts/ports;

https://gist.github.com/Geolim4/69471ccd398f2a919f109063ecc0c971#file-setup-and-options-md

I would assume the proper way to set it would be like this;

$InstanceCache = CacheManager::getInstance("memcached", ['host' => "127.0.0.1",'port' => 3333]);
$key = "product_page";
$CachedString = $InstanceCache->getItem($key);
if (is_null($CachedString->get())) {
    //$CachedString = "APC Cache --> Cache Enabled --> Well done !";
    // Write products to Cache in 10 minutes with same keyword
    $CachedString->set("Memcached Cache --> Cache Enabled --> Well done !")->expiresAfter(120);
    $InstanceCache->save($CachedString);
    echo "FIRST LOAD // WROTE OBJECT TO CACHE // RELOAD THE PAGE AND SEE // ";
    echo $CachedString->get();
} else {
    echo "READ FROM CACHE // ";
    echo $CachedString->get();
}

But the code never gets to "READ FROM CACHE". Am I supposed to set up the host/port somewhere else?


Solution

  • Are you the author of this issue ? If not, I suggest you to have a look at it.

    Cheers, Georges