2017 © Pedro Peláez
 

library simple-cache

Simple cache service.

image

mesavolt/simple-cache

Simple cache service.

  • Monday, June 11, 2018
  • by chteuchteu
  • Repository
  • 1 Watchers
  • 1 Stars
  • 62 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

SimpleCache

Latest Stable Version Build Status Coverage Status License, (*1)

Simple cache system based on Symfony's Cache component. Will always return a value, fresh or from cache, depending on TTL., (*2)

Installation

composer require mesavolt/simple-cache

Usage

<?php

use Mesavolt\SimpleCache;

$cache = new SimpleCache(sys_get_temp_dir());
$ttl = 10; // values expire after 10 seconds

// use the cache for the 1st, the callable is executed, a fresh value is cached and returned
$value1 = $cache->get('key', function () {
    return time();
}, $ttl);

// use the cache again before TTL has passed.
// the callable is *not* executed again, the previously cached value is returned
$value2 = $cache->get('key', function () {
    return time();
}, $ttl);

assert($value2 === $value1); // true because TTL hasn't expired

// sleep 20 seconds, this is longer that our TTL of 10 seconds
sleep(20);

// use the cache for the 3rd time, TTL has expired so a new fresh value is cached and returned
$value3 = $cache->get('key', function () {
    return time();
});

assert($value3 !== $value1); // true because `sleep(20)` expired the TTL
                             // so the callable has been executed
                             // and a fresh value has been returned (and cached)

The Versions

11/06 2018

dev-develop

dev-develop

Simple cache service.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar mesavolt

cache simple simple-cache

11/06 2018

v0.0.2

0.0.2.0

Simple cache service.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar mesavolt

cache simple simple-cache

06/06 2018

v0.0.1

0.0.1.0

Simple cache service.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar mesavolt

cache simple simple-cache