Skip to content

Commit

Permalink
Merge pull request #2 from byjg/4.0
Browse files Browse the repository at this point in the history
4.0
  • Loading branch information
byjg authored May 27, 2017
2 parents d844b55 + 337c29f commit 1ec8b03
Show file tree
Hide file tree
Showing 25 changed files with 1,116 additions and 680 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ addons:
- redis-container

php:
- "7.1"
- "7.0"
- "5.6"

before_install:
- echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini

install:
- composer install

script:
script:
- phpunit --stderr
60 changes: 39 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,55 @@

## Description

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

## Avaible cache engines
## Cache Engine PSR-16 compliant

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:

| Class | Description |
|:----------------------------------------|:--------------------------------------------------------------------|
| \ByJG\Cache\Psr16\NoCacheEngine | Do nothing. Use it for disable the cache without change your code |
| \ByJG\Cache\Psr16\ArrayCacheEngine | Local cache only using array. It does not persists between requests |
| \ByJG\Cache\Psr16\FileSystemCacheEngine | Save the cache result in the local file system |
| \ByJG\Cache\Psr16\MemcachedEngine | Uses the Memcached as the cache engine |
| \ByJG\Cache\Psr16\SessionCachedEngine | uses the PHP session as cache |
| \ByJG\Cache\Psr16\ShmopCachedEngine | uses the shared memory area for cache |

To create a new Cache Instance just create the proper cache engine and use it:

| Class | Description |
|:----------------------------------|:--------------------------------------------------------------------|
| \ByJG\Cache\NoCacheEngine | Do nothing. Use it for disable the cache without change your code |
| \ByJG\Cache\ArrayCacheEngine | Local cache only using array. It does not persists between requests |
| \ByJG\Cache\FileSystemCacheEngine | Save the cache result in the local file system |
| \ByJG\Cache\MemcachedEngine | Uses the Memcached as the cache engine |
| \ByJG\Cache\SessionCachedEngine | uses the PHP session as cache |
| \ByJG\Cache\ShmopCachedEngine | uses the shared memory area for cache |
```php
<?php
$cache = new \ByJG\Cache\Psr16\FileSystemCacheEngine();

// And use it:
$object = $cache->get('key');
$cache->set('key', 'value');
if ($cache->has('key')) {
//...
};
```

## Create new cache instance
## Cache Engine PSR-6 compliant

### Creating a PSR-6 compatible instance
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.

You can set instance in the 'cacheconfig.php' setup (see below how to configure the factory)
You can use one of the factory methods to create a instance of the CachePool implementation:

```php
<?php
$cachePool = \ByJG\Cache\Factory::createFilePool();
```

or you can create the CachePool imediatelly:
OR just create a new CachePool and pass to the constructor an instance of a PSR-16 compliant class:

```php
$cachePool = new CachePool(new FileSystemCacheEngine());
```

### Logging cache commands

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


### List of Avaiable Factory Commands
## List of Avaiable Factory Commands

**Note: All parameters are optional**

Expand All @@ -62,9 +76,13 @@ The Commom 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

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

## Install

Just type: `composer require "byjg/cache-engine=3.0.*"`
Just type: `composer require "byjg/cache-engine=4.0.*"`


## Running Unit Testes
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "byjg/cache-engine",
"description": "A multi-purpose cache engine in PHP with several drivers. PSR-6 compliant.",
"description": "A multi-purpose cache engine PSR-6 and PSR-16 implementation with several drivers.",
"authors": [
{
"name": "João Gilberto Magalhães",
Expand All @@ -15,7 +15,8 @@
"require": {
"php": ">=5.4.0",
"psr/cache": "1.0.*",
"psr/log": "1.0.2"
"psr/log": "1.0.2",
"psr/simple-cache": "1.0.*"
},
"suggest": {
"ext-memcached": "*"
Expand Down
13 changes: 13 additions & 0 deletions src/CacheAvailabilityInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace ByJG\Cache;


interface CacheAvailabilityInterface
{
/**
* Return if this CacheEngine is available for use
* @return bool
*/
public function isAvailable();
}
55 changes: 0 additions & 55 deletions src/CacheEngineInterface.php

This file was deleted.

24 changes: 24 additions & 0 deletions src/CacheLockInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* User: jg
* Date: 26/05/17
* Time: 01:38
*/

namespace ByJG\Cache;


interface CacheLockInterface
{
/**
* Lock resource before set it.
* @param string $key
*/
public function lock($key);

/**
* Unlock resource
* @param string $key
*/
public function unlock($key);
}
102 changes: 0 additions & 102 deletions src/Engine/ArrayCacheEngine.php

This file was deleted.

Loading

0 comments on commit 1ec8b03

Please sign in to comment.