GithubHelp home page GithubHelp logo

runt18 / cache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from joomla-framework/cache

0.0 2.0 0.0 104 KB

Joomla Framework Cache Package

License: GNU General Public License v2.0

PHP 100.00%

cache's Introduction

The Cache Package Build Status

Latest Stable Version Total Downloads Latest Unstable Version License

This cache package is based on a version of the now accepted PSR-6 as it was in 2013.

Options and General Usage

Following option as available across a cache storage types:

  • ttl - Time to live.
use Joomla\Cache;

$options = array(
	'ttl' => 900,
);

$cache = new Cache\Runtime($options);

// Set a value in the cache.
$cache->set('key', 'value');

// Get the value back.
$value = $cache->get('key')->getValue();

// Remove the item from the cache.
$cache->remove('key');

// Clear all the items from the cache.
$cache->clear();

// Get multiple values from the cache at once.
$values = $cache->getMultiple(array('key1', 'key2'));

// Set multiple values from the cache at once.
$values = $cache->setMultiple(array('key1' => 'value1', 'key2' => 'value2'));

// Remove multiple values from the cache at once.
$values = $cache->removeMultiple(array('key1', 'key2'));

Cache Storage Types

The following storage types are supported.

Apc

use Joomla\Cache;

$cache = new Cache\Apc;

File

The File cache allows the following additional options:

  • file.path - the path where the cache files are to be stored.
  • file.locking
use Joomla\Cache;

$options = array(
	'file.path' => __DIR__ . '/cache',
);

$cache = new Cache\File($options);

Memcached

use Joomla\Cache;

$cache = new Cache\Memcached;

None

use Joomla\Cache;

$cache = new Cache\None;

Runtime

use Joomla\Cache;

$cache = new Cache\Runtime;

Wincache

use Joomla\Cache;

$cache = new Cache\Wincache;

XCache

use Joomla\Cache;

$cache = new Cache\XCache;

Test Mocking

The Cache package provide a PHPUnit helper to mock a Cache\Cache object or an Cache\Item object. You can include your own optional overrides in the test class for the following methods:

  • Cache\Cache::get: Add a method called mockCacheGet to your test class. If omitted, the helper will return a default mock for the Cache\Item class.
  • Cache\Item::getValue: Add a method called mockCacheItemGetValue to your test class. If omitted, the mock Cache\Item will return "value" when this method is called.
  • Cache\Item::isHit: Add a method called mockCacheItemIsHit to your test class. If omitted, the mock Cache\Item will return false when this method is called.
use Joomla\Cache\Tests\Mocker as CacheMocker;

class FactoryTest extends \PHPUnit_Framework_TestCase
{
	private $instance;

	//
	// The following mocking methods are optional.
	//

	/**
	 * Callback to mock the Cache\Item::getValue method.
	 *
	 * @return  string
	 */
	public function mockCacheItemGetValue()
	{
		// This is the default handling.
		// You can override this method to provide a custom return value.
		return 'value';
	}

	/**
	 * Callback to mock the Cache\Item::isHit method.
	 *
	 * @return  boolean
	 */
	public function mockCacheItemIsHit()
	{
		// This is the default handling.
		// You can override this method to provide a custom return value.
		return false;
	}

	/**
	 * Callback to mock the Cache\Cache::get method.
	 *
	 * @param   string  $text  The input text.
	 *
	 * @return  string
	 */
	public function mockCacheGet($key)
	{
		// This is the default handling.
		// You can override this method to provide a custom return value.
		return $this->createMockItem();
	}

	protected function setUp()
	{
		parent::setUp();

		$mocker = new CacheMocker($this);

		$this->instance = new SomeClass($mocker->createMockCache());
	}
}

Installation via Composer

Add "joomla/cache": "~1.0" to the require block in your composer.json and then run composer install.

{
	"require": {
		"joomla/cache": "~1.0"
	}
}

Alternatively, you can simply run the following from the command line:

composer require joomla/cache "~1.0"

cache's People

Contributors

achal-aggarwal avatar aliasm2k avatar asika32764 avatar dongilbert avatar eddieajau avatar gamort avatar ianmacl avatar jindrichpilar avatar mbabker avatar pborreli avatar photodude avatar realityking avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.