aol / cachelink-client-php

此包已废弃且不再维护。未建议替代包。

用于cachelink-service的PHP客户端

10.0.1 2017-08-25 16:59 UTC

README

用于AOL cachelink的PHP客户端。

Build Status Coverage Status Latest Stable Version Latest Unstable Version License

安装

composer require aol/cachelink-client-php

用法

<?php

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

许可协议

版权所有 © 2013 AOL, Inc.

保留所有权利。

MIT