Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/joshuaestes/kash

General Purpose PHP Caching Library
https://github.com/joshuaestes/kash

Last synced: 1 day ago
JSON representation

General Purpose PHP Caching Library

Awesome Lists containing this project

README

        

Kash/Kash [![Travis](https://img.shields.io/travis/JoshuaEstes/Kash.svg)](https://travis-ci.org/JoshuaEstes/Kash) [![Packagist Pre Release](https://img.shields.io/packagist/vpre/kash/kash.svg)](https://packagist.org/packages/kash/kash) [![Packagist](https://img.shields.io/packagist/v/kash/kash.svg)](https://packagist.org/packages/kash/kash)
=========

[![Code Climate](https://img.shields.io/codeclimate/github/JoshuaEstes/Kash.svg)](https://codeclimate.com/github/JoshuaEstes/Kash) [![Code Climate](https://img.shields.io/codeclimate/coverage/github/JoshuaEstes/Kash.svg)](https://codeclimate.com/github/JoshuaEstes/Kash)

Kash is a general purpose caching library that is used to cache various values
using a variety of different drivers to accomplish this.

* Database results
* User sessions
* API Calls

# Features

* Fast
* Supports
* Filesystem
* APC
* Redis
* Memcached
* PDO
* Null
* Extra drivers that are able to support multiple backends
* Uses PSR-3 standard for logging
* Heavily Tested, Commented, and Quality Controlled

# Installation

## Composer (Preferred)

This assumes you have [composer] installed. Once you do that please run

```bash
composer.phar require "kash/kash:*"
```

# Usage

```php
setLogger($logger);

// Get an item base on a unique key. If the item does
// not exist, it creates one for you
/** @var \Kash\CacheItemInterface */
$item = $pool->getItem('example_key');

if (!$item->isHit()) {
// ... do stuff, put results into $value
$item->set($value);

// Expires in 300 seconds from now
$item->setExpiration(300);

// Save the item to your cache
$pool->save($item);
}

// $result is whatever you had it set to
$result = $item->get();

// Delete the item from the cache
$pool->deleteItems(array($item));

// Clear the backend cache of all items
$pool->clear();
```

# Configure Kash as a Service with Symfony2

Edit your `services.xml` file.

```xml




```

This will set up Kash and use [Monolog] as the logger or whatever you have setup
as the logging service. You can change the driver class to whatever driver you
want.

When you need to use the caching service, simple grab it out of the container.

```php
// Inside your controller, inside an action
$pool = $this->get('cache_pool');
```

# Core Concepts

## Items

Items are the smallest unit that can be cached. This would include the results
from an API call or possible just a simple value. Items are what you will use to
cache data and check expiration times.

## Pools

Items go into and come out of a pool. The pool uses Drivers to talk with various
Backends.

## Drivers

Drivers are used to communicate with cache Backends such as a filesytem,
database, etc. The only know of the Backend they need to communicate with and
that they are given CacheItem's to find and persist.

## Backends

Backends are anything that is used to store cached items. These include things
such as a filesystem up to Redis and everything in between.

# Drivers

## NullDriver

The `NullDriver` does not cache any data.

## ArrayDriver

This driver caches data in an `array`. It does not persist data, but you are
able to set values and expire items.

### Usage

```php