-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f80d3c5
commit 5c53e05
Showing
7 changed files
with
120 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php namespace Ltb\Cache; | ||
|
||
use Symfony\Component\Cache\Adapter\FilesystemAdapter; | ||
|
||
class FileCache extends \Ltb\Cache\Cache{ | ||
|
||
public function __construct( | ||
$namespace = 'ltbCache', | ||
$defaultLifetime = 0, | ||
$directory = null | ||
) | ||
{ | ||
|
||
$this->cache = new FilesystemAdapter( | ||
$namespace, | ||
$defaultLifetime, | ||
$directory | ||
); | ||
|
||
// Clean cache from expired entries | ||
$this->cache->prune(); | ||
|
||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php namespace Ltb\Cache; | ||
|
||
use Symfony\Component\Cache\Adapter\RedisAdapter; | ||
|
||
class RedisCache extends \Ltb\Cache\Cache{ | ||
|
||
public function __construct( | ||
$redis_url, | ||
$namespace = 'ltbCache', | ||
$defaultLifetime = 0, | ||
) | ||
{ | ||
|
||
$redis_connection = RedisAdapter::createConnection( $redis_url ); | ||
|
||
$this->cache = new RedisAdapter( | ||
$redis_connection, | ||
$namespace, | ||
$defaultLifetime, | ||
); | ||
|
||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
final class FileCacheTest extends \Mockery\Adapter\Phpunit\MockeryTestCase | ||
{ | ||
|
||
public function test_construct(): void | ||
{ | ||
$cacheInstance = new \Ltb\Cache\FileCache( | ||
"testCache", | ||
0, | ||
null | ||
); | ||
$this->assertTrue($cacheInstance->cache instanceof Symfony\Component\Cache\Adapter\FilesystemAdapter, "Error while initializing cache object"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
final class RedisCacheTest extends \Mockery\Adapter\Phpunit\MockeryTestCase | ||
{ | ||
|
||
public function test_construct(): void | ||
{ | ||
$redis_url = "dummy"; | ||
$redis_connection = "redis_connection"; | ||
$namespace = "ltbCache"; | ||
$defaultLifetime = 0; | ||
|
||
$redisAdapterMock = Mockery::mock('overload:Symfony\Component\Cache\Adapter\RedisAdapter'); | ||
|
||
$redisAdapterMock->shouldreceive('createConnection') | ||
->with( $redis_url ) | ||
->andReturn( $redis_connection ); | ||
|
||
$redisAdapterMock->shouldReceive('__construct') | ||
->once() | ||
->with( | ||
$redis_connection, | ||
$namespace, | ||
$defaultLifetime | ||
); | ||
|
||
$cacheInstance = new \Ltb\Cache\RedisCache( | ||
$redis_url, | ||
$namespace, | ||
$defaultLifetime | ||
); | ||
$this->assertTrue($cacheInstance->cache instanceof Symfony\Component\Cache\Adapter\RedisAdapter, "Error while initializing Redis cache object"); | ||
} | ||
|
||
|
||
} |