Skip to content

Commit

Permalink
Merge pull request #5 from byjg/issue-4
Browse files Browse the repository at this point in the history
Fix PSR-4 name issue #4
  • Loading branch information
byjg authored Feb 2, 2021
2 parents f6ba962 + eb82eb3 commit 24fe2fc
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 97 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ addons:
- redis-container

php:
- "7.4"
- "7.3"
- "7.2"
- "7.1"
Expand All @@ -24,3 +25,11 @@ install:

script:
- vendor/bin/phpunit --stderr

jobs:
include:
- stage: documentation
if: branch = master
before_install: skip
install: skip
script: "curl https://opensource.byjg.com/add-doc.sh | bash /dev/stdin php cache-engine-php"
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Cache Engine

[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg.com-brightgreen.svg)](http://opensource.byjg.com)
[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg-success.svg)](http://opensource.byjg.com)
[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/cache-engine-php/)
[![GitHub license](https://img.shields.io/github/license/byjg/cache-engine-php.svg)](https://opensource.byjg.com/opensource/licensing.html)
[![GitHub release](https://img.shields.io/github/release/byjg/cache-engine-php.svg)](https://github.com/byjg/cache-engine-php/releases/)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/byjg/cache-engine-php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/byjg/cache-engine-php/?branch=master)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/f643fd22-8ab1-4f41-9bef-f9f9e127ec0d/mini.png)](https://insight.sensiolabs.com/projects/f643fd22-8ab1-4f41-9bef-f9f9e127ec0d)
[![Build Status](https://travis-ci.org/byjg/cache-engine-php.svg?branch=master)](https://travis-ci.org/byjg/cache-engine-php)
[![Build Status](https://travis-ci.com/byjg/cache-engine-php.svg?branch=master)](https://travis-ci.com/byjg/cache-engine-php)



A multi-purpose cache engine PSR-6 and PSR-16 implementation with several drivers.

# Cache Engine PSR-16 compliant
## PSR-16

PSR-16 defines a Simple Cache interface with less verbosity than PSR-6. Below a list
of engines available in this library that is PSR-16 compliant:
Expand Down Expand Up @@ -44,7 +47,7 @@ $object = $cache->get('key');

See more PSR-16 examples [here](docs/basic-usage-psr16-simplecache.md)

# Cache Engine PSR-6 compliant
## PSR-6

The PSR-6 implementation use the engines defined above. PSR-6 is more verbosity and
have an extra layer do get and set the cache values.
Expand All @@ -64,7 +67,7 @@ $cachePool = new CachePool(new FileSystemCacheEngine());

See more PSR-6 examples [here](docs/basic-usage-psr6-cachepool.md)

# List of Available Factory Commands
## List of Available Factory Commands

**Note: All parameters are optional**

Expand All @@ -88,7 +91,7 @@ The Common parameters are:
- servers: An array of memcached servers. E.g.: `[ '127.0.0.1:11211' ]`
- config: Specific setup for shmop. E.g.: `[ 'max-size' => 524288, 'default-permission' => '0700' ]`

# Logging cache commands
## Logging cache commands

You can add a PSR Log compatible to the constructor in order to get Log of the operations

Expand All @@ -103,7 +106,7 @@ composer require "byjg/cache-engine=4.0.*"
```


# Running Unit Testes
## Running Unit Testes

```
phpunit --stderr
Expand Down
66 changes: 0 additions & 66 deletions _config.yml

This file was deleted.

10 changes: 2 additions & 8 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
<?php
/**
* User: jg
* Date: 27/05/17
* Time: 12:21
*/

namespace ByJG\Cache;
namespace ByJG\Cache\Exception;


class InvalidArgumentException extends \Exception implements \Psr\Cache\InvalidArgumentException
class InvalidArgumentException extends \Exception implements \Psr\Cache\InvalidArgumentException, \Psr\SimpleCache\InvalidArgumentException
{

}
9 changes: 9 additions & 0 deletions src/Exception/StorageErrorException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php


namespace ByJG\Cache\Exception;

class StorageErrorException extends \Exception
{

}
5 changes: 2 additions & 3 deletions src/Psr16/BaseCacheEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ByJG\Cache\Psr16;

use ByJG\Cache\CacheAvailabilityInterface;
use ByJG\Cache\InvalidArgumentException;
use ByJG\Cache\Exception\InvalidArgumentException;
use Psr\SimpleCache\CacheInterface;

abstract class BaseCacheEngine implements CacheInterface, CacheAvailabilityInterface
Expand All @@ -12,7 +12,6 @@ abstract class BaseCacheEngine implements CacheInterface, CacheAvailabilityInter
* @param $keys
* @param null $default
* @return array|iterable
* @throws \ByJG\Cache\InvalidArgumentException
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function getMultiple($keys, $default = null)
Expand Down Expand Up @@ -68,4 +67,4 @@ protected function addToNow($ttl)

return null;
}
}
}
17 changes: 9 additions & 8 deletions src/Psr16/MemcachedEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ByJG\Cache\Psr16;

use ByJG\Cache\Exception\StorageErrorException;
use Memcached;
use Psr\Log\NullLogger;

Expand Down Expand Up @@ -38,7 +39,7 @@ protected function fixKey($key) {
}

/**
* @throws \Exception
* @throws StorageErrorException
*/
protected function lazyLoadMemCachedServers()
{
Expand All @@ -50,7 +51,7 @@ protected function lazyLoadMemCachedServers()

$stats = $this->memCached->getStats();
if (!isset($stats[$server]) || $stats[$server]['pid'] === -1) {
throw new \Exception("Memcached server $server is down");
throw new StorageErrorException("Memcached server $server is down");
}
}
}
Expand All @@ -60,7 +61,7 @@ protected function lazyLoadMemCachedServers()
* @param string $key The object KEY
* @param int $default IGNORED IN MEMCACHED.
* @return mixed Description
* @throws \Exception
* @throws StorageErrorException
*/
public function get($key, $default = null)
{
Expand All @@ -80,7 +81,7 @@ public function get($key, $default = null)
* @param object $value The object to be cached
* @param int $ttl The time to live in seconds of this objects
* @return bool If the object is successfully posted
* @throws \Exception
* @throws StorageErrorException
*/
public function set($key, $value, $ttl = null)
{
Expand All @@ -98,7 +99,7 @@ public function set($key, $value, $ttl = null)
/**
* @param string $key
* @return bool
* @throws \Exception
* @throws StorageErrorException
*/
public function delete($key)
{
Expand All @@ -117,14 +118,14 @@ public function isAvailable()
try {
$this->lazyLoadMemCachedServers();
return true;
} catch (\Exception $ex) {
} catch (StorageErrorException $ex) {
return false;
}
}

/**
* @return bool
* @throws \Exception
* @throws StorageErrorException
*/
public function clear()
{
Expand All @@ -136,7 +137,7 @@ public function clear()
/**
* @param string $key
* @return bool
* @throws \Exception
* @throws StorageErrorException
*/
public function has($key)
{
Expand Down
8 changes: 5 additions & 3 deletions src/Psr16/ShmopCacheEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace ByJG\Cache\Psr16;

use Psr\Cache\InvalidArgumentException;
use ByJG\Cache\Exception\InvalidArgumentException;
use ByJG\Cache\Exception\StorageErrorException;
use Psr\Log\NullLogger;

/**
Expand Down Expand Up @@ -125,6 +126,7 @@ protected function isValidAge($file)
* for it or let the driver take care of that.
* @return bool True on success and false on failure.
* @throws InvalidArgumentException
* @throws StorageErrorException
*/
public function set($key, $value, $ttl = null)
{
Expand All @@ -136,7 +138,7 @@ public function set($key, $value, $ttl = null)
$size = strlen($serialized);

if ($size > $this->getMaxSize()) {
throw new \ByJG\Cache\InvalidArgumentException('Object is greater than the max size allowed: ' . $this->getMaxSize());
throw new StorageErrorException('Object is greater than the max size allowed: ' . $this->getMaxSize());
}

$file = $this->getFilenameToken($key);
Expand All @@ -148,7 +150,7 @@ public function set($key, $value, $ttl = null)
if (isset($lastError['message'])) {
$message = $lastError['message'];
}
throw new \ByJG\Cache\InvalidArgumentException($message);
throw new StorageErrorException($message);
}

$shm_bytes_written = shmop_write($shm_id, $serialized, 0);
Expand Down
3 changes: 1 addition & 2 deletions src/Psr6/CachePool.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace ByJG\Cache\Psr6;

use ByJG\Cache\Exception\InvalidArgumentException;
use ByJG\Cache\Psr16\BaseCacheEngine;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\InvalidArgumentException;

class CachePool implements CacheItemPoolInterface
{
Expand Down Expand Up @@ -204,7 +204,6 @@ public function deleteItems(array $keys)
* @param CacheItemInterface $item
* @return bool
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function save(CacheItemInterface $item)
{
Expand Down

0 comments on commit 24fe2fc

Please sign in to comment.