Skip to content

Commit

Permalink
Patch simple cache (#131)
Browse files Browse the repository at this point in the history
* Added test and fixed minor bug

* Added meta files

* Added class comment

* Updated integration test version

* Require Symfony for testing

* Require mockery
  • Loading branch information
Nyholm authored Jan 5, 2017
1 parent f4330b2 commit d72c007
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor/
composer.lock

22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: php
sudo: false

matrix:
include:
- php: 7.0

cache:
directories:
- "$HOME/.composer/cache"

install:
- composer update

script:
- ./vendor/bin/phpunit --coverage-clover=coverage.xml

after_success:
- pip install --user codecov && codecov

notifications:
email: false
9 changes: 9 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Change Log

The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.

## UNRELEASED

## 0.1.0

First release
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Aaron Scherer, Tobias Nyholm

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# PSR-6 to PSR-16 Bridge (Simple cache)
[![Gitter](https://badges.gitter.im/php-cache/cache.svg)](https://gitter.im/php-cache/cache?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Latest Stable Version](https://poser.pugx.org/cache/simple-cache-bridge/v/stable)](https://packagist.org/packages/cache/simple-cache-bridge)
[![codecov.io](https://codecov.io/github/php-cache/simple-cache-bridge/coverage.svg?branch=master)](https://codecov.io/github/array-cache/apc-adapter?branch=master)
[![Total Downloads](https://poser.pugx.org/cache/simple-cache-bridge/downloads)](https://packagist.org/packages/cache/simple-cache-bridge)
[![Monthly Downloads](https://poser.pugx.org/cache/simple-cache-bridge/d/monthly.png)](https://packagist.org/packages/cache/simple-cache-bridge)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)

This is a PSR-6 cache implementation using PHP array. It is a part of the PHP Cache organisation. To read about
features like tagging and hierarchy support please read the shared documentation at [www.php-cache.com](http://www.php-cache.com).

### Install

```bash
composer require cache/simple-cache-bridge
```

### Use

You need an existing PSR-6 pool as a cnstructor argument to the bridge.

```php
$psr6pool = new ArrayCachePool();
$simpleCache = new SimpleCacheBridge($psr6pool);
```

### Contribute

Contributions are very welcome! Send a pull request to the [main repository](https://github.com/php-cache/cache) or
report any issues you find on the [issue tracker](http://issues.php-cache.com).
14 changes: 12 additions & 2 deletions SimpleCacheBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
use Psr\Cache\InvalidArgumentException as CacheInvalidArgumentException;
use Psr\SimpleCache\CacheInterface;

/**
* Adds a SimpleCache interface on a PSR-6 cache pool.
*
* @author Magnus Nordlander <magnus@fervo.se>
*/
class SimpleCacheBridge implements CacheInterface
{
/**
Expand Down Expand Up @@ -57,12 +62,12 @@ public function set($key, $value, $ttl = null)
{
try {
$item = $this->cacheItemPool->getItem($key);
$item->expiresAfter($ttl);
} catch (CacheInvalidArgumentException $e) {
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}

$item->set($value);
$item->expiresAfter($ttl);

return $this->cacheItemPool->save($item);
}
Expand Down Expand Up @@ -144,7 +149,12 @@ public function setMultiple($values, $ttl = null)
foreach ($items as $key => $item) {
/* @var $item CacheItemInterface */
$item->set($values[$key]);
$item->expiresAfter($ttl);

try {
$item->expiresAfter($ttl);
} catch (CacheInvalidArgumentException $e) {
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}

$itemSuccess = $itemSuccess && $this->cacheItemPool->saveDeferred($item);
}
Expand Down
24 changes: 24 additions & 0 deletions Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of php-cache organization.
*
* (c) 2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Cache\Bridge\SimpleCache\Tests;

use Cache\Bridge\SimpleCache\SimpleCacheBridge;
use Cache\IntegrationTests\SimpleCacheTest as BaseTest;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

class IntegrationTest extends BaseTest
{
public function createSimpleCache()
{
return new SimpleCacheBridge(new ArrayAdapter());
}
}
48 changes: 48 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "cache/simple-cache-bridge",
"description": "A PSR-6 bridge to PSR-16. This will make any PSR-6 cache compatible with SimpleCache.",
"type": "library",
"license": "MIT",
"minimum-stability": "dev",
"keywords": [
"cache",
"psr-6",
"psr-16",
"bridge"
],
"homepage": "http://www.php-cache.com/en/latest/",
"authors": [
{
"name": "Magnus Nordlander",
"email": "magnus@fervo.se",
"homepage": "https://github.com/magnusnordlander"
}
],
"require": {
"php": "^5.5 || ^7.0",
"psr/cache": "^1.0",
"psr/simple-cache": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0 || ^5.1",
"cache/integration-tests": "^0.14",
"mockery/mockery": "^0.9",
"symfony/cache": "^3.2"
},
"provide": {
"psr/simple-cache-implementation": "^1.0"
},
"autoload": {
"psr-4": {
"Cache\\Bridge\\SimpleCache\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"extra": {
"branch-alias": {
"dev-master": "0.2-dev"
}
}
}
35 changes: 35 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Main Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>

<groups>
<exclude>
<group>benchmark</group>
</exclude>
</groups>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

0 comments on commit d72c007

Please sign in to comment.