Skip to content

Commit 495b435

Browse files
committed
Added more documentation
1 parent deec7d0 commit 495b435

11 files changed

+228
-14
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ of engines available in this library that is PSR-16 compliant:
1616

1717
{:.table}
1818

19-
| Class | Description |
20-
|:----------------------------------------|:--------------------------------------------------------------------|
21-
| \ByJG\Cache\Psr16\NoCacheEngine | Do nothing. Use it for disable the cache without change your code |
22-
| \ByJG\Cache\Psr16\ArrayCacheEngine | Local cache only using array. It does not persists between requests |
23-
| \ByJG\Cache\Psr16\FileSystemCacheEngine | Save the cache result in the local file system |
24-
| \ByJG\Cache\Psr16\MemcachedEngine | Uses the Memcached as the cache engine |
25-
| \ByJG\Cache\Psr16\SessionCachedEngine | uses the PHP session as cache |
26-
| \ByJG\Cache\Psr16\ShmopCachedEngine | uses the shared memory area for cache |
19+
| Class | Description |
20+
|:---------------------------------------------------------------------------------|:--------------------------------------------------------------------|
21+
| [\ByJG\Cache\Psr16\NoCacheEngine](docs/class-no-cache-engine.md) | Do nothing. Use it for disable the cache without change your code |
22+
| [\ByJG\Cache\Psr16\ArrayCacheEngine](docs/class-array-cache-engine.md) | Local cache only using array. It does not persists between requests |
23+
| [\ByJG\Cache\Psr16\FileSystemCacheEngine](docs/class-filesystem-cache-engine.md) | Save the cache result in the local file system |
24+
| [\ByJG\Cache\Psr16\MemcachedEngine](docs/class-memcached-engine.md) | Uses the Memcached as the cache engine |
25+
| [\ByJG\Cache\Psr16\RedisCachedEngine](docs/class-redis-cache-engine.md) | uses the Redis as cache |
26+
| [\ByJG\Cache\Psr16\SessionCachedEngine](docs/class-session-cache-engine.md) | uses the PHP session as cache |
27+
| [\ByJG\Cache\Psr16\ShmopCachedEngine](docs/class-shmop-cache-engine.md) | uses the shared memory area for cache |
2728

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

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}
88
},
99
"require": {
10-
"php": ">=5.6.0",
10+
"php": ">=7.0",
1111
"psr/cache": "^1.0",
1212
"psr/log": "^1.1",
1313
"psr/simple-cache": "^1.0"

docs/class-array-cache-engine.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Class ArrayCacheEngine
2+
3+
This class is a simple cache engine that uses an array to store the values.
4+
It does not persists between requests.
5+
6+
It is ideal to use on unit tests or when you need a simple cache engine.
7+
8+
9+
## PSR-16 Constructor
10+
11+
```php
12+
$cache = new \ByJG\Cache\Psr16\ArrayCacheEngine()
13+
```
14+
15+
## PSR-6 Constructor
16+
17+
```php
18+
$cachePool = \ByJG\Cache\Factory::createArrayPool()
19+
```
20+
21+
or
22+
23+
```php
24+
$cachePool = new \ByJG\Cache\Psr6\CachePool(new \ByJG\Cache\Psr16\ArrayCacheEngine());
25+
```
26+
27+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Class FilesystemCacheEngine
2+
3+
This class uses the Filesystem as the cache engine.
4+
5+
## Defining the Path
6+
7+
The FileSystemCacheEngine expects a prefix and a path to store the cache files.
8+
The prefix is used to avoid collision between different applications using the same cache path.
9+
If the path is not defined, the default is the system temporary path.
10+
11+
12+
## PSR-16 Constructor
13+
14+
```php
15+
$cache = new \ByJG\Cache\Psr16\FileSystemCacheEngine($path, $prefix)
16+
```
17+
18+
## PSR-6 Constructor
19+
20+
```php
21+
$cachePool = \ByJG\Cache\Factory::createFilePool($path, $prefix, $bufferSize = 10)
22+
```
23+
24+
or
25+
26+
```php
27+
$cachePool = new \ByJG\Cache\Psr6\CachePool(new \ByJG\Cache\Psr16\FileSystemCacheEngine($path, $prefix));
28+
```
29+
30+

docs/class-memcached-engine.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Class MemcachedEngine
2+
3+
This class uses the Memcached as the cache engine.
4+
5+
## Defining the Servers
6+
7+
The constructor expects an array of servers.
8+
Each server is an item in the array with the following format:
9+
10+
```php
11+
$servers = [
12+
'localhost:11211',
13+
]
14+
```
15+
16+
## PSR-16 Constructor
17+
18+
```php
19+
$cache = new \ByJG\Cache\Psr16\MemcachedEngine($servers)
20+
```
21+
22+
## PSR-6 Constructor
23+
24+
```php
25+
$cachePool = \ByJG\Cache\Factory::createMemcachedPool($servers)
26+
```
27+
28+
or
29+
30+
```php
31+
$cachePool = new \ByJG\Cache\Psr6\CachePool(new \ByJG\Cache\Psr16\MemcachedEngine($servers));
32+
```
33+
34+

docs/class-no-cache-engine.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Class NoCacheEngine
2+
3+
This class don't cache. Use it for disable the cache without change your code.
4+
5+
6+
## PSR-16 Constructor
7+
8+
```php
9+
$cache = new \ByJG\Cache\Psr16\NoCacheEngine();
10+
```
11+
12+
## PSR-6 Constructor
13+
14+
```php
15+
$cachePool = \ByJG\Cache\Factory::createNullPool();
16+
```
17+
18+
or
19+
20+
```php
21+
$cachePool = new \ByJG\Cache\Psr6\CachePool(new \ByJG\Cache\Psr16\NoCacheEngine());
22+
```
23+
24+

docs/class-redis-cache-engine.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Class RedisCacheEngine
2+
3+
This class uses the Redis as the cache engine.
4+
5+
## Defining the Servers
6+
7+
The constructor expects a string with the server and port.
8+
9+
```php
10+
$server = 'localhost:5678'
11+
```
12+
13+
## PSR-16 Constructor
14+
15+
```php
16+
$cache = new \ByJG\Cache\Psr16\RedisCacheEngine($server, $password)
17+
```
18+
19+
## PSR-6 Constructor
20+
21+
```php
22+
$cachePool = \ByJG\Cache\Factory::createRedisCacheEngine($server, $password)
23+
```
24+
25+
or
26+
27+
```php
28+
$cachePool = new \ByJG\Cache\Psr6\CachePool(new \ByJG\Cache\Psr16\RedisCacheEngine($server, $password));
29+
```
30+
31+

docs/class-session-cache-engine.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Class SessionCacheEngine
2+
3+
This class uses the PHP Session as the cache engine.
4+
This will persist the cache between requests while the user session is active.
5+
6+
The cache is not shared between different users.
7+
8+
9+
## PSR-16 Constructor
10+
11+
```php
12+
$cache = new \ByJG\Cache\Psr16\SessionCacheEngine($prefix)
13+
```
14+
15+
## PSR-6 Constructor
16+
17+
```php
18+
$cachePool = \ByJG\Cache\Factory::createSessionPool($prefix, $bufferSize = 10)
19+
```
20+
21+
or
22+
23+
```php
24+
$cachePool = new \ByJG\Cache\Psr6\CachePool(new \ByJG\Cache\Psr16\SessionCacheEngine($prefix));
25+
```
26+
27+

docs/class-shmop-cache-engine.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Class ShmopCacheEngine
2+
3+
This class uses the PHP Shmop as the cache engine.
4+
5+
The Shared memory allows multiple processes to access the same data in memory.
6+
You can use it to share data among running PHP scripts in the same server.
7+
8+
## Configuration
9+
10+
These are the default values for the configuration:
11+
12+
```php
13+
$config = [
14+
'max-size' => 524288, // 512Kb
15+
'default-permission' = > '0700',
16+
];
17+
```
18+
19+
20+
## PSR-16 Constructor
21+
22+
```php
23+
$cache = new \ByJG\Cache\Psr16\ShmopCacheEngine($config, $prefix)
24+
```
25+
26+
## PSR-6 Constructor
27+
28+
```php
29+
$cachePool = \ByJG\Cache\Factory::createSessionPool($prefix, $bufferSize = 10)
30+
```
31+
32+
or
33+
34+
```php
35+
$cachePool = new \ByJG\Cache\Psr6\CachePool(new \ByJG\Cache\Psr16\ShmopCacheEngine($config, $prefix));
36+
```
37+
38+

src/Factory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public static function createSessionPool($prefix = null, $bufferSize = null)
2828
);
2929
}
3030

31-
public static function createFilePool($prefix = null, $bufferSize = null, $logger = null)
31+
public static function createFilePool($prefix = null, $path = null, $bufferSize = null, $logger = null)
3232
{
3333
return new CachePool(
34-
new FileSystemCacheEngine($prefix, $logger),
34+
new FileSystemCacheEngine($prefix, $path, $logger),
3535
$bufferSize
3636
);
3737
}

0 commit comments

Comments
 (0)