• Stars
    star
    134
  • Rank 270,153 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple cache library. Implements different adapters that you can use and change easily by a manager or similar.

Desarolla2 Cache

A simple cache library, implementing the PSR-16 standard using immutable objects.

life-is-hard-cache-is

Caching is typically used throughout an applicatiton. Immutability ensure that modifying the cache behaviour in one location doesn't result in unexpected behaviour due to changes in unrelated code.

Desarolla2 Cache aims to be the most complete, correct and best performing PSR-16 implementation available.

Latest version Latest version Software License Build Status Coverage Status Quality Score Total Downloads Today Downloads Gitter

Installation

composer require desarrolla2/cache

Usage

use Desarrolla2\Cache\Memory as Cache;

$cache = new Cache();

$value = $cache->get('key');

if (!isset($value)) {
    $value = do_something(); 
    $cache->set('key', $value, 3600);
}

echo $value;

Adapters

The following implementation allows you to combine cache adapters.

Options

You can set options for cache using the withOption or withOptions method. Note that all cache objects are immutable, setting an option creates a new object.

TTL

All cache implementations support the ttl option. This sets the default time (in seconds) that cache will survive. It defaults to one hour (3600 seconds).

Setting the TTL to 0 or a negative number, means the cache should live forever.

Methods

PSR-16 methods

Each cache implementation has the following Psr\SimpleCache\CacheInterface methods:

get(string $key [, mixed $default])

Retrieve the value corresponding to a provided key

has(string $key)

Retrieve the if value corresponding to a provided key exist

set(string $key, mixed $value [, int $ttl])

Add a value to the cache under a unique key

delete(string $key)

Delete a value from the cache

clear()

Clear all cache

getMultiple(array $keys)

Obtains multiple cache items by their unique keys

setMultiple(array $values [, int $ttl])

Persists a set of key => value pairs in the cache

deleteMultiple(array $keys)

Deletes multiple cache items in a single operation

Additional methods

The Desarrolla2\Cache\CacheInterface also has the following methods:

withOption(string $key, string $value)

Set option for implementation. Creates a new instance.

withOptions(array $options)

Set multiple options for implementation. Creates a new instance.

getOption(string $key)

Get option for implementation.

Packers

Cache objects typically hold a Desarrolla2\Cache\Packer\PackerInterface object. By default, packing is done using serialize and unserialize.

Available packers are:

  • SerializePacker using serialize and unserialize
  • JsonPacker using json_encode and json_decode
  • NopPacker does no packing
  • MongoDBBinaryPacker using serialize and unserialize to store as BSON Binary

PSR-16 incompatible packers

The JsonPacker does not fully comply with PSR-16, as packing and unpacking an object will probably not result in an object of the same class.

The NopPacker is intended when caching string data only (like HTML output) or if the caching backend supports structured data. Using it when storing objects will might give unexpected results.

Contributors

Daniel González Twitter: @desarrolla2
Arnold Daniels Twitter: @ArnoldDaniels

More Repositories

1

RSSClient

Service for provide RSS client in your website
PHP
34
star
2

BlogBundle

This is the most complete bundle you can find to start creating your blog, actualy this blogBundle is running on Symfony2.3
PHP
22
star
3

RSSClientBundle

Service for provide RSS client in your website.
PHP
9
star
4

PollBundle

poll Bundle for symfony 2
PHP
8
star
5

talks

some of my talks
PHP
7
star
6

File

Provide simple api to read and write files
PHP
4
star
7

download-bundle

This bundle allows you to download a database and folders associated with the project from remote host to local machine. It is the easiest and easiest way to have the same production data in your development environment.
PHP
4
star
8

Timer

This script works as simple timer control to your app
PHP
4
star
9

MailExceptionBundle

Email you when Symfony2 Exceptions occurs with some information.
PHP
4
star
10

DoctrineMirrorBundle

PHP
3
star
11

Gmap

PHP
3
star
12

PlanetBundle

PHP
3
star
13

Logger

PHP
2
star
14

inspector

This project analyzes a git repository and reports on the modifications that have been made to it by each of the users.
PHP
2
star
15

Booky

PHP
2
star
16

imager

JavaScript
2
star
17

TwitterClientBundle

TwitterClientBundle
PHP
1
star
18

FormBundle

PHP
1
star
19

SystemMonitorBundle

SystemMonitorBundle
PHP
1
star
20

d2LibsPlugin

PHP
1
star
21

twitter-oauth

PHP
1
star
22

DB

PHP
1
star
23

TwitterClient

PHP
1
star
24

MenuBundle

PHP
1
star
25

dotfiles

Here are my personal dot files, i use this repository to share some of my configs about several computers, you can use it to get any ideas about how i work, but be careful is possible that this repository is not updated.
Shell
1
star
26

Exporter

PHP
1
star
27

test-bundle

This bundle allows you to perform functional tests quickly and easily with symfony.
PHP
1
star
28

demo-PollBundle

this proyets its a demo for poll bundle
JavaScript
1
star
29

WebBundle

PHP
1
star