Skip to content

Commit

Permalink
bugfix/2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kodeart authored Dec 8, 2019
1 parent b006d5c commit d6dac1c
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build
vendor
.idea
.DS_Store
composer.lock
*.yml
.env
!.travis.yml
*.cache
22 changes: 22 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
build:
nodes:
analysis:
tests:
stop_on_failure: true
override:
- php-scrutinizer-run
environment:
php:
version: '7.2'
dependencies:
override:
- composer install --no-interaction --prefer-source

filter:
excluded_paths:
- 'Tests/'
- 'vendor/'

tools:
php_analyzer: true
external_code_coverage: true
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ script:
- vendor/bin/phpunit --coverage-clover build/coverage/clover.xml

after_success:
- travis_retry vendor/bin/codacycoverage clover build/coverage/clover.xml
- travis_retry vendor/bin/ocular code-coverage:upload --format=php-clover build/coverage/clover.xml
2 changes: 1 addition & 1 deletion CacheException.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function forUnsupportedLogger(string $supported, string $given)

public static function forCreatingDirectory(string $directory)
{
return new static(Cache::E_DIRECTORY_NOT_CREATED, [':dir' => $directory]);
return new self(Cache::E_DIRECTORY_NOT_CREATED, [':dir' => $directory]);
}


Expand Down
2 changes: 1 addition & 1 deletion Client/CacheClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private function createMemcachedClient(MemcachedConfiguration $conf): Cache
$client->addServers($conf->getServers());
}

return new MemcachedClient($client, $conf->get('ttl'));
return new MemcachedClient($client, $conf->getTtl());
}

/**
Expand Down
17 changes: 16 additions & 1 deletion Configuration/MemcachedConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function __construct(array $options = [])
\Memcached::OPT_REMOVE_FAILED_SERVERS => true,
\Memcached::OPT_RETRY_TIMEOUT => 1,
\Memcached::OPT_PREFIX_KEY => null
], $options['options'] ?? [])
], $options['options'] ?? []),
'ttl' => $options['ttl'] ?? null
]);
}

Expand Down Expand Up @@ -99,4 +100,18 @@ public function getOptions(): array
return null !== $value;
});
}

/**
* Returns the global TTL in seconds, or NULL for never-expire value.
*
* @return int|null
*/
public function getTtl(): ?int
{
if (null === $ttl = $this->get('ttl')) {
return null;
}

return (int)$ttl;
}
}
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Koded - Simple Caching Library

[![Latest Stable Version](https://img.shields.io/packagist/v/koded/cache-simple.svg)](https://packagist.org/packages/koded/cache-simple)
[![Build Status](https://travis-ci.org/kodedphp/cache-simple.svg?branch=master)](https://travis-ci.org/kodedphp/cache-simple)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/1b3bad367cc74a3fa98996c252cdfe6f)](https://www.codacy.com/app/kodeart/cache-simple)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1b3bad367cc74a3fa98996c252cdfe6f)](https://www.codacy.com/app/kodeart/cache-simple)
[![Code Coverage](https://scrutinizer-ci.com/g/kodedphp/cache-simple/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/kodedphp/cache-simple/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/kodedphp/cache-simple/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/kodedphp/cache-simple/?branch=master)
[![Packagist Downloads](https://img.shields.io/packagist/dt/koded/cache-simple.svg)](https://packagist.org/packages/koded/cache-simple)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.2-8892BF.svg)](https://php.net/)
[![Software license](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](LICENSE)
Expand Down Expand Up @@ -160,6 +160,7 @@ $cache = simple_cache_factory('redis', [
| id | string | no | Memcached persistent_id value |
| servers | array | no | A list of nested array with \[server, port\] values |
| options | array | no | A list of Memcached options |
| ttl | int | no | Global TTL (in seconds) |

The following options are set **by default** when instance of `MemcachedConfiguration` is created,
except for `OPT_PREFIX_KEY` which is there as a reminder that it may be set
Expand Down Expand Up @@ -198,7 +199,10 @@ Examples:
\Memcached::OPT_PREFIX_KEY => 'i:', // item prefix
\Memcached::OPT_REMOVE_FAILED_SERVERS => false, // change the default value
\Memcached::OPT_DISTRIBUTION => null // remove this directive
]
],

// the global expiration time (for ALL cached items)
'ttl' => 120,
]
```

Expand Down
18 changes: 18 additions & 0 deletions Tests/ClientFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ public function test_should_create_memcached_client()
$this->assertInstanceOf(MemcachedClient::class, $client);
}

/**
* @depends test_should_create_memcached_client
*/
public function test_should_create_memcached_client_with_ttl()
{
if (false === extension_loaded('Memcached')) {
$this->markTestSkipped('Memcached is not installed on this environment.');
}

$client = (new CacheClientFactory(new ConfigFactory(['ttl' => 120])))->new('memcached');

$r = new \ReflectionClass($client);
$ttl = $r->getProperty('ttl');
$ttl->setAccessible(true);

$this->assertSame(120, $ttl->getValue($client));
}

public function test_should_create_redis_client()
{
if (false === extension_loaded('redis')) {
Expand Down
12 changes: 12 additions & 0 deletions Tests/Configuration/MemcachedConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public function test_should_build_default_arguments()
], $config->getOptions());
}

public function test_should_set_the_ttl()
{
$config = new MemcachedConfiguration(['ttl' => 120]);
$this->assertSame(120, $config->getTtl());

$config = new MemcachedConfiguration(['ttl' => '120']);
$this->assertSame(120, $config->getTtl());

$config = new MemcachedConfiguration;
$this->assertNull($config->getTtl());
}

protected function tearDown(): void
{
putenv('MEMCACHED_POOL=');
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0
2.2.0
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"mikey179/vfsstream": "~1",
"predis/predis": "dev-master",
"cache/integration-tests": "dev-master",
"codacy/coverage": "dev-master",
"symfony/phpunit-bridge": "^4.4@dev"
"symfony/phpunit-bridge": "^4.4@dev",
"scrutinizer/ocular": "^1.6"
},
"extra": {
"branch-alias": {
Expand Down

0 comments on commit d6dac1c

Please sign in to comment.