Skip to content

Commit 1ec8b03

Browse files
authored
Merge pull request #2 from byjg/4.0
4.0
2 parents d844b55 + 337c29f commit 1ec8b03

25 files changed

+1116
-680
lines changed

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ addons:
1010
- redis-container
1111

1212
php:
13+
- "7.1"
1314
- "7.0"
1415
- "5.6"
1516

17+
before_install:
18+
- echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
19+
- echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
20+
1621
install:
1722
- composer install
1823

19-
script:
24+
script:
2025
- phpunit --stderr

README.md

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,55 @@
66

77
## Description
88

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

11-
## Avaible cache engines
11+
## Cache Engine PSR-16 compliant
12+
13+
PSR-16 defines a Simple Cache interface with less verbosity than PSR-6. Below a list
14+
of engines available in this library that is PSR-16 compliant:
15+
16+
| Class | Description |
17+
|:----------------------------------------|:--------------------------------------------------------------------|
18+
| \ByJG\Cache\Psr16\NoCacheEngine | Do nothing. Use it for disable the cache without change your code |
19+
| \ByJG\Cache\Psr16\ArrayCacheEngine | Local cache only using array. It does not persists between requests |
20+
| \ByJG\Cache\Psr16\FileSystemCacheEngine | Save the cache result in the local file system |
21+
| \ByJG\Cache\Psr16\MemcachedEngine | Uses the Memcached as the cache engine |
22+
| \ByJG\Cache\Psr16\SessionCachedEngine | uses the PHP session as cache |
23+
| \ByJG\Cache\Psr16\ShmopCachedEngine | uses the shared memory area for cache |
24+
25+
To create a new Cache Instance just create the proper cache engine and use it:
1226

13-
| Class | Description |
14-
|:----------------------------------|:--------------------------------------------------------------------|
15-
| \ByJG\Cache\NoCacheEngine | Do nothing. Use it for disable the cache without change your code |
16-
| \ByJG\Cache\ArrayCacheEngine | Local cache only using array. It does not persists between requests |
17-
| \ByJG\Cache\FileSystemCacheEngine | Save the cache result in the local file system |
18-
| \ByJG\Cache\MemcachedEngine | Uses the Memcached as the cache engine |
19-
| \ByJG\Cache\SessionCachedEngine | uses the PHP session as cache |
20-
| \ByJG\Cache\ShmopCachedEngine | uses the shared memory area for cache |
27+
```php
28+
<?php
29+
$cache = new \ByJG\Cache\Psr16\FileSystemCacheEngine();
30+
31+
// And use it:
32+
$object = $cache->get('key');
33+
$cache->set('key', 'value');
34+
if ($cache->has('key')) {
35+
//...
36+
};
37+
```
2138

22-
## Create new cache instance
39+
## Cache Engine PSR-6 compliant
2340

24-
### Creating a PSR-6 compatible instance
41+
The PSR-6 implementation use the engines defined above. PSR-6 is more verbosity and
42+
have an extra layer do get and set the cache values.
2543

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

2846
```php
47+
<?php
2948
$cachePool = \ByJG\Cache\Factory::createFilePool();
3049
```
3150

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

3453
```php
3554
$cachePool = new CachePool(new FileSystemCacheEngine());
3655
```
3756

38-
### Logging cache commands
39-
40-
You can add a PSR Log compatible to the constructor in order to get Log of the operations
41-
42-
43-
### List of Avaiable Factory Commands
57+
## List of Avaiable Factory Commands
4458

4559
**Note: All parameters are optional**
4660

@@ -62,9 +76,13 @@ The Commom parameters are:
6276
- servers: An array of memcached servers. E.g.: `[ '127.0.0.1:11211' ]`
6377
- config: Specific setup for shmop. E.g.: `[ 'max-size' => 524288, 'default-permission' => '0700' ]`
6478

79+
## Logging cache commands
80+
81+
You can add a PSR Log compatible to the constructor in order to get Log of the operations
82+
6583
## Install
6684

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

6987

7088
## Running Unit Testes

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "byjg/cache-engine",
3-
"description": "A multi-purpose cache engine in PHP with several drivers. PSR-6 compliant.",
3+
"description": "A multi-purpose cache engine PSR-6 and PSR-16 implementation with several drivers.",
44
"authors": [
55
{
66
"name": "João Gilberto Magalhães",
@@ -15,7 +15,8 @@
1515
"require": {
1616
"php": ">=5.4.0",
1717
"psr/cache": "1.0.*",
18-
"psr/log": "1.0.2"
18+
"psr/log": "1.0.2",
19+
"psr/simple-cache": "1.0.*"
1920
},
2021
"suggest": {
2122
"ext-memcached": "*"

src/CacheAvailabilityInterface.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace ByJG\Cache;
4+
5+
6+
interface CacheAvailabilityInterface
7+
{
8+
/**
9+
* Return if this CacheEngine is available for use
10+
* @return bool
11+
*/
12+
public function isAvailable();
13+
}

src/CacheEngineInterface.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/CacheLockInterface.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* User: jg
4+
* Date: 26/05/17
5+
* Time: 01:38
6+
*/
7+
8+
namespace ByJG\Cache;
9+
10+
11+
interface CacheLockInterface
12+
{
13+
/**
14+
* Lock resource before set it.
15+
* @param string $key
16+
*/
17+
public function lock($key);
18+
19+
/**
20+
* Unlock resource
21+
* @param string $key
22+
*/
23+
public function unlock($key);
24+
}

src/Engine/ArrayCacheEngine.php

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)