PHP code example of aol / cachelink-client-php

1. Go to this page and download the library: Download aol/cachelink-client-php 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/ */

    

aol / cachelink-client-php example snippets




use Aol\CacheLink\CacheLinkClient;

// The base URL for where the cache service is hosted.
$cache_service_base_url = 'http://localhost:8899';

// The timeout in seconds for talking to the service (this is optional).
$timeout = 3;

// Whether to set detailed data in cachelink for retrieval later (TTL, associations, metadata, etc.).
$set_detailed = true;

// Create the client.
$cache = new CacheLinkClient($cache_service_base_url, $timeout, $set_detailed);

// Add a Predis client for direct redis gets.
$cache->setupDirectRedis(new \Predis\Client(...));

// Set a value.
$cache->set('foo', 'bar', 3000);

// Get a value - outputs "bar".
echo $cache->get('foo')->getValue();

// Clear "foo".
$cache->clear(['foo']);

$cache = new CacheLinkClient(...);

$items = $cache->getMany(['foo', 'bar', 'baz']);

foreach ($items as $item) {
	$item->getKey();          // The cache key for the item.
	$item->isHit();           // Whether the item is a cache hit.
	$item->isMiss();          // Whether the item is a cache miss.
	$item->getValue();        // The value from cache, null if there was none.
	$item->getTtlMillis();    // The item's original TTL in millis or null if none.
	$item->getMetadata();     // The item's original metadata or an empty array if none.
	$item->getAssociations(); // The item's original associations or an empty array if none.
}

$cache = new CacheLinkClient(...);

// Get the value for the "foo" key from cache or null if a miss.
$value = $cache->getSimple('foo');

// Get the values for the "foo", "bar", and "baz" keys from cache or nulls if misses.
$values = $cache->getManySimple(['foo', 'bar', 'baz']);

composer