2017 © Pedro Peláez
 

library delayed-cache

Delayed cache for php

image

koine/delayed-cache

Delayed cache for php

  • Thursday, September 24, 2015
  • by mjacobus
  • Repository
  • 1 Watchers
  • 0 Stars
  • 515 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Koine Delayed Cache

Delayed Cache is a wrapper for Zend Cache. Sometimes you have parallel requests want a cached result that was already started, but is still under construction. Delayed cache will wait until it is ready and then it will return the result for you., (*1)

Code information:, (*2)

Build Status Coverage Status Code Climate Scrutinizer Code Quality, (*3)

Package information:, (*4)

Latest Stable Version Total Downloads Latest Unstable Version License Dependency Status, (*5)

Installing

Installing via Composer

Append the lib to your requirements key in your composer.json., (*6)

{
    // composer.json
    // [..]
    require: {
        // append this line to your requirements
        "koine/delayed-cache": "dev-master"
    }
}

Alternative install

Usage

$zendCache = $cache  = \Zend\Cache\StorageFactory::adapterFactory(
    'apc',
    array('ttl' => 3600)
);

$delayedCache = new \Koine\DelayedCache\DelayedCache($zendCache);
// index.php, second 10:00:00 am

$cacheKey = 'veryExpansiveCalculation';

$veryExpansiveCalculation = function () {
    sleep(60);

    return '42';
};

// hasItem returns true in the false time
if (!$delayedCache->hasItem($cacheKey)) {
    $delayedCache->setItem($cacheKey, $veryExpansiveCalculation);
}

$answer = $delayedCache->getItem($cacheKey);
echo 'answer is: ' . $answer;
// index.php, 10:00:10 am

$cacheKey = 'veryExpansiveCalculation';

$veryExpansiveCalculation = function () {
    sleep(60);

    return '42';
};

// although the result is not ready yet, hasItem will return true
if (!$delayedCache->hasItem($cacheKey)) {
    $delayedCache->setItem($cacheKey, $veryExpansiveCalculation);
}

// Waits 50 seconds until the building of the cache is done and then returns
// The $veryExpansiveCalculation callback will not be executed twice, unless the
// cache is cleared
$answer = $delayedCache->getItem($cacheKey);
echo 'answer is: ' . $answer;

Alternatively you can use the short method:, (*7)

$cacheKey = 'veryExpansiveCalculation';

$veryExpansiveCalculation = function () {
    sleep(60);

    return '42';
};

// if cache is not set, it will set and then return the cached value
$answer = $delayedCache->getCachedItem($cacheKey, $veryExpansiveCalculation);
echo 'answer is: ' . $answer;

When it shines, (*8)

Issues/Features proposals

Here is the issue tracker., (*9)

Contributing

Only TDD code will be accepted. Please follow the PSR-2 code standard., (*10)

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

How to run the tests:

phpunit

To check the code standard run:

# Fixes code
./bin/php-cs-fix.sh

# outputs error
./bin/php-cs-fix.sh src true
./bin/php-cs-fix.sh test true

Lincense

MIT, (*11)

Authors

The Versions

24/09 2015

dev-master

9999999-dev

Delayed cache for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marcelo Jacobus

24/09 2015

v1.0.2

1.0.2.0

Delayed cache for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marcelo Jacobus

17/09 2015

v1.0.1

1.0.1.0

Delayed cache for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marcelo Jacobus

04/09 2015

v1.0

1.0.0.0

Delayed cache for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marcelo Jacobus