Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: zendframework/zend-cache
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: release-2.8.2
Choose a base ref
...
head repository: zendframework/zend-cache
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: release-2.8.3
Choose a head ref

Commits on May 1, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    leohemsted Leo Hemsted
    Copy the full SHA
    94280cb View commit details
  2. Bumped version

    weierophinney committed May 1, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    csmarchbanks Chris Marchbanks
    Copy the full SHA
    72c16e4 View commit details

Commits on Jul 2, 2018

  1. Copy the full SHA
    8b69f8f View commit details

Commits on Mar 24, 2019

  1. Fix typos in exception messages and code comments

    Done with codespell's dictionary.
    
    No impact is expected unless callers directly check exception messages.
    TysonAndre committed Mar 24, 2019
    Copy the full SHA
    1b83f1c View commit details
  2. Copy the full SHA
    742c91d View commit details

Commits on Mar 29, 2019

  1. Fixes cache entry deletion directly after creation

    See
    #183
    
    Only set TTL if there is a value which is not null!
    Al3x Zamponi authored Mar 29, 2019
    Copy the full SHA
    e291cd7 View commit details
  2. Update SimpleCacheDecorator.php

    Al3x Zamponi authored Mar 29, 2019
    Copy the full SHA
    9167e2b View commit details

Commits on Apr 1, 2019

  1. fixed whitespaces

    Al3x Zamponi authored Apr 1, 2019
    Copy the full SHA
    9d8479e View commit details

Commits on Aug 14, 2019

  1. count optimization

    samsonasik authored and michalbundyra committed Aug 14, 2019
    Copy the full SHA
    778b83b View commit details
  2. Merge pull request #172 from samsonasik/count-op

    count optimization
    michalbundyra committed Aug 14, 2019
    Copy the full SHA
    2f426da View commit details
  3. Swap yoda conditions

    We tend not to use yoda comaprision as there are less readable
    michalbundyra committed Aug 14, 2019
    Copy the full SHA
    8ae461c View commit details
  4. Merge pull request #173 from samsonasik/substr-strpos

    change substr with strpos/stripos when possible
    michalbundyra committed Aug 14, 2019
    Copy the full SHA
    216a885 View commit details
  5. Updates configuration of MkDocs for documentation

    - fixes page name - Home
    - removes unneeded copyright info
    - updates site description
    michalbundyra committed Aug 14, 2019
    Copy the full SHA
    dc81371 View commit details
  6. Merge pull request #187 from webimpress/hotfix/docs-config

    Close #187
    
    Updates configuration of MkDocs for documentation
    michalbundyra committed Aug 14, 2019
    Copy the full SHA
    1d6fa9d View commit details
  7. Copy the full SHA
    035b012 View commit details
  8. Adds test to check TTL on set/setMultiple of SimpleCacheDecorator

    We should use TTL from options when it is not provided on set/setMultiple
    methods of SimpleCacheDecorator.
    michalbundyra committed Aug 14, 2019
    Copy the full SHA
    96fa750 View commit details

Commits on Aug 15, 2019

  1. Copy the full SHA
    284eaed View commit details
  2. Copy the full SHA
    7672066 View commit details
  3. Copy the full SHA
    b022dd6 View commit details
  4. Update Travis CI config to fix memcache/memcached tests on PHP 5.6

    It looks like memcache/memcached services are no longer installed
    properly on Travis when using PHP 5.6, so we need to use pecl command
    to install them.
    michalbundyra committed Aug 15, 2019
    Copy the full SHA
    04280d9 View commit details
  5. Merge pull request #188 from froschdesign/hotfix/docs/headlines-index…

    …-versionnotes
    
    Close #188
    
    Fixes and updates for documentation
    michalbundyra committed Aug 15, 2019
    Copy the full SHA
    96032d9 View commit details
  6. Merge pull request #189 from webimpress/hotfix/travis-ci

    Close #189
    
    Update Travis CI config to fix memcache/memcached tests on PHP 5.6
    michalbundyra committed Aug 15, 2019
    Copy the full SHA
    c970c44 View commit details

Commits on Aug 28, 2019

  1. Merge pull request #184 from alexz707/patch-1

    Fixes cache entry deletion directly after creation
    michalbundyra committed Aug 28, 2019
    Copy the full SHA
    8ec6aa7 View commit details
  2. Copy the full SHA
    187c862 View commit details
  3. Copy the full SHA
    50d1077 View commit details
  4. Copy the full SHA
    ff370bf View commit details
  5. Copy the full SHA
    b3ac682 View commit details
  6. Merge branch 'hotfix/184'

    Close #184
    Fix #183
    michalbundyra committed Aug 28, 2019
    Copy the full SHA
    e92dade View commit details
  7. Merge pull request #182 from webimpress/hotfix/181

    Hotfix: Use the provided database name of the resource
    michalbundyra committed Aug 28, 2019
    Copy the full SHA
    3f8cc58 View commit details
  8. Copy the full SHA
    60cac73 View commit details
  9. Copy the full SHA
    3ff38aa View commit details
  10. Remove unused import

    michalbundyra committed Aug 28, 2019
    Copy the full SHA
    b6ba249 View commit details
  11. Merge branch 'hotfix/182'

    Close #182
    Fix #181
    michalbundyra committed Aug 28, 2019
    Copy the full SHA
    e5660fb View commit details
  12. Copy the full SHA
    acb2e19 View commit details
  13. Copy the full SHA
    edde41f View commit details
1 change: 0 additions & 1 deletion .ci/memcache.ini

This file was deleted.

13 changes: 11 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -44,6 +44,8 @@ matrix:
env:
- DEPS=lowest
- APCU_PECL_VERSION="apcu-4.0.8"
- MEMCACHE_PECL_VERSION="memcache-2.2.7"
- MEMCACHED_PECL_VERSION="memcached-2.2.0"
- TESTS_ZEND_CACHE_EXTMONGODB_ENABLED=false
- TESTS_ZEND_CACHE_MEMCACHE_ENABLED=true
- TESTS_ZEND_CACHE_XCACHE_ENABLED=true
@@ -52,13 +54,17 @@ matrix:
- DEPS=locked
- LEGACY_DEPS="phpbench/phpbench phpunit/phpunit"
- APCU_PECL_VERSION="apcu-4.0.10"
- MEMCACHE_PECL_VERSION="memcache-3.0.7"
- MEMCACHED_PECL_VERSION="memcached-2.2.0"
- TESTS_ZEND_CACHE_EXTMONGODB_ENABLED=false
- TESTS_ZEND_CACHE_MEMCACHE_ENABLED=true
- TESTS_ZEND_CACHE_XCACHE_ENABLED=true
- php: 5.6
env:
- DEPS=latest
- APCU_PECL_VERSION="apcu-4.0.11"
- MEMCACHE_PECL_VERSION="memcache-3.0.8"
- MEMCACHED_PECL_VERSION="memcached-2.2.0"
- TESTS_ZEND_CACHE_EXTMONGODB_ENABLED=false
- TESTS_ZEND_CACHE_MEMCACHE_ENABLED=true
- TESTS_ZEND_CACHE_XCACHE_ENABLED=true
@@ -126,6 +132,7 @@ matrix:

before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- pecl channel-update pecl.php.net

install:
# prevent PECL from enabling the extension by default, see https://pear.php.net/bugs/bug.php?id=21007
@@ -159,10 +166,12 @@ install:
fi ;

- if [[ $TESTS_ZEND_CACHE_MEMCACHE_ENABLED == 'true' ]]; then
phpenv config-add .ci/memcache.ini ;
yes|CFLAGS="-fgnu89-inline" pecl install -f $MEMCACHE_PECL_VERSION ;
fi ;

- if [[ $TESTS_ZEND_CACHE_MEMCACHED_ENABLED == 'true' ]]; then
- if [[ $TESTS_ZEND_CACHE_MEMCACHED_ENABLED == 'true' && $TRAVIS_PHP_VERSION =~ ^5.6 ]]; then
echo "no" | pecl install -f $MEMCACHED_PECL_VERSION ;
elif [[ $TESTS_ZEND_CACHE_MEMCACHED_ENABLED == 'true' ]]; then
phpenv config-add .ci/memcached.ini ;
fi ;

29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,35 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.8.3 - 2019-08-28

### Added

- Nothing.

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- [#184](https://github.com/zendframework/zend-cache/pull/184) fixes
an issue with SimpleCacheDecorator where elements were deleted
after creation. Wrong TTL was set instead of using default value
from options.

- [#182](https://github.com/zendframework/zend-cache/pull/182) fixes
a typo in variable name within the `ExtMongoDbResourceManager::getResource`
method which prevented using custom db name when using that adapter.

## 2.8.2 - 2018-05-01

### Added
11 changes: 0 additions & 11 deletions docs/book/index.html

This file was deleted.

2 changes: 1 addition & 1 deletion docs/book/pattern/callback-cache.md
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ class CallbackCache extends AbstractPattern

## Examples

### Instantiating the callback cache pattern
### Instantiating the Callback Cache Pattern

```php
use Zend\Cache\PatternFactory;
2 changes: 1 addition & 1 deletion docs/book/pattern/capture-cache.md
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ class CaptureCache extends AbstractPattern

## Examples

### Scaling images in the web root
### Scaling Images in the Web Root

Using the following Apache 404 configuration:

2 changes: 1 addition & 1 deletion docs/book/pattern/class-cache.md
Original file line number Diff line number Diff line change
@@ -131,7 +131,7 @@ class ClassCache extends CallbackCache

## Examples

**Caching of import feeds**
### Caching of Import Feeds

```php
$cachedFeedReader = Zend\Cache\PatternFactory::factory('class', [
2 changes: 1 addition & 1 deletion docs/book/pattern/intro.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Zend\\Cache\\Pattern
# Introduction

Cache patterns are configurable objects that solve known performance
bottlenecks. Each should be used only in the specific situations they are
2 changes: 1 addition & 1 deletion docs/book/pattern/object-cache.md
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ class ObjectCache extends CallbackCache

## Examples

### Caching a filter
### Caching a Filter

```php
$filter = new Zend\Filter\RealPath();
2 changes: 1 addition & 1 deletion docs/book/pattern/output-cache.md
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ class OutputCache extends AbstractPattern

## Examples

### Caching simple view scripts
### Caching simple View Scripts

```php
$outputCache = Zend\Cache\PatternFactory::factory('output', [
6 changes: 3 additions & 3 deletions docs/book/psr16.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PSR-16 Support
# PSR-16

- Since 2.8.0
> Available since version 2.8.0
[PSR-16](https://www.php-fig.org/psr/psr-16/) provides a simplified approach to
cache access that does not involve cache pools, tags, deferment, etc.; it
@@ -100,7 +100,7 @@ $cache = StorageFactory::factory([
]);
```

## Deleting items and exceptions
## Deleting Items and Exceptions

PSR-16 states that the `delete()` and `deleteMultiple()` methods should return
`false` if an _error_ occured when deleting the key(s) provided, but `true`
10 changes: 5 additions & 5 deletions docs/book/psr6.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PSR-6 Support
# PSR-6

- Since 2.8.0
> Available since version 2.8.0
## Overview

@@ -51,7 +51,7 @@ values like an empty string, `null`, or `false` can be stored. Always check `isH
found.


## Supported adapters
## Supported Adapters

The PSR-6 specification requires that the underlying storage support time-to-live (TTL), which is set when the
item is saved. For this reason the following adapters cannot be used: `Dba`, `Filesystem`, `Memory` and `Session`. The
@@ -77,7 +77,7 @@ actually saved to storage. If this is set when you instantiate the pool it will
behaviour.


## Logging errors
## Logging Errors

The specification [states](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-6-cache.md#error-handling):

@@ -126,7 +126,7 @@ Note that `throw_exceptions` should always be `true` (the default) or you will n
calls on the pool such as `save()`.


## Supported data types
## Supported Data Types

As per [the specification](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-6-cache.md#data), the
following data types can be stored in cache: `string`, `integer`, `float`, `boolean`, `null`, `array`, `object` and be
30 changes: 15 additions & 15 deletions docs/book/storage/adapter.md
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ these are then passed to an options class instance). Alternately, you can pass
either the options instance or associative array to the
`Zend\Cache\StorageFactory::factory` method.

> ### Many methods throw exceptions
> ### Many Methods throw Exceptions
>
> Because many caching operations throw an exception on error, you need to catch
> them. You can do so manually, or you can use the plugin
@@ -555,7 +555,7 @@ Capability | Value
`namespaceIsPrefix` | `true`
`namespaceSeparator` | Option value of `namespace_separator`

### Adapter specific options
### Adapter specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -589,7 +589,7 @@ Capability | Value
`namespaceIsPrefix` | `true`
`namespaceSeparator` | Option value of `namespace_separator`

### Adapter specific options
### Adapter specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -636,7 +636,7 @@ Capability | Value
`namespaceIsPrefix` | `true`
`namespaceSeparator` | Option value of `namespace_separator`

### Adapter specific options
### Adapter specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -686,7 +686,7 @@ Capability | Value
`namespaceIsPrefix` | `true`
`namespaceSeparator` | none

### Adapter specific options
### Adapter specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -719,7 +719,7 @@ Capability | Value
`namespaceIsPrefix` | `true`
`namespaceSeparator` | none

### Adapter specific options
### Adapter specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -768,13 +768,13 @@ Capability | Value
`maxKeyLength` | 0
`namespaceIsPrefix` | `false`

### Adapter specific options
### Adapter specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
`memory_limit` | `string|integer` | 50% of `memory_limit` INI value | Limit of how much memory can PHP allocate to allow store items.

> #### Memory limit
> #### Memory Limit
>
> The adapter has the following behavior with regards to the memory limit:
>
@@ -820,7 +820,7 @@ Capability | Value
`namespaceIsPrefix` | `true`
`namespaceSeparator` | <Option value of namespace_separator>

### Adapter specific options
### Adapter specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -839,7 +839,7 @@ Key | Default | Description

## The ExtMongoDB Adapter

- Since 2.8.0
> Available since version 2.8.0
`Zend\Cache\Storage\Adapter\ExtMongoDB` stores cache items using the mongodb extension, and
requires that the MongoDB PHP Client library is also installed. You can install the client
@@ -874,7 +874,7 @@ Capability | Value
`namespaceIsPrefix` | `true`
`namespaceSeparator` | <Option value of namespace_separator>

### Adapter specific options
### Adapter specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -918,7 +918,7 @@ Capability | Value
`namespaceIsPrefix` | `true`
`namespaceSeparator` | Option value of `namespace_separator`

### Adapter specific options
### Adapter specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -955,7 +955,7 @@ Capability | Value
`namespaceIsPrefix` | `true`
`namespaceSeparator` | Option value of `namespace_separator`

### Adapter specific options
### Adapter specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -1023,7 +1023,7 @@ Capability | Value

## Examples

### Basic usage
### Basic Usage

```php
use Zend\Cache\StorageFactory;
@@ -1048,7 +1048,7 @@ if (! $success) {
}
```

### Get multiple rows from a database
### Get multiple Rows from a Database

```php
use Zend\Cache\StorageFactory;
4 changes: 2 additions & 2 deletions docs/book/storage/capabilities.md
Original file line number Diff line number Diff line change
@@ -263,7 +263,7 @@ class Capabilities

## Examples

### Get storage capabilities and do specific stuff based on them
### Get Storage Capabilities and do specific Stuff based on them

```php
use Zend\Cache\StorageFactory;
@@ -279,7 +279,7 @@ if ($supportedDatatypes['object']) {
}
```

### Listen to the change event
### Listen to the change Event

```php
use Zend\Cache\StorageFactory;
14 changes: 7 additions & 7 deletions docs/book/storage/plugin.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Storage Plugins
# Plugins

Cache storage plugins are objects that provide additional functionality to or
influence behavior of a storage adapter.
@@ -45,7 +45,7 @@ $cache->addPlugin($plugin);
`clearExpired()` randomly (by factor) after every call of `setItem()`,
`setItems()`, `addItem()`, and `addItems()`.

### Plugin specific options
### Plugin specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -62,7 +62,7 @@ Name | Data Type | Default Value | Description
reading from or writing to the cache, and sends the exception to a defined callback function.
You may also configure the plugin to re-throw exceptions.

### Plugin specific options
### Plugin specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -74,7 +74,7 @@ Name | Data Type | Default Value | Description
`Zend\Cache\Storage\Plugin\IgnoreUserAbort` ignores user-invoked script
termination when, allowing cache write operations to complete first.

### Plugin specific options
### Plugin specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -85,7 +85,7 @@ Name | Data Type | Default Value | Description
`Zend\Cache\Storage\Plugin\OptimizeByFactor` calls the storage method `optimize()`
randomly (by factor) after removing items from the cache.

### Plugin specific options
### Plugin specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -102,7 +102,7 @@ Name | Data Type | Default Value | Description
cache, and deserialize when reading. This allows storing datatypes not supported
by the underlying storage adapter.

### Plugin specific options
### Plugin specific Options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
@@ -163,7 +163,7 @@ interface PluginInterface extends ListenerAggregateInterface

## Examples

### Basic plugin implementation
### Basic Plugin Implementation

```php
use Zend\Cache\Storage\Event;
5 changes: 2 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
docs_dir: docs/book
site_dir: docs/html
pages:
- index.md
- Home: index.md
- Storage:
- Adapters: storage/adapter.md
- Capabilities: storage/capabilities.md
@@ -17,6 +17,5 @@ pages:
- PSR-6: psr6.md
- PSR-16: psr16.md
site_name: zend-cache
site_description: Zend\Cache
site_description: 'Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output.'
repo_url: 'https://github.com/zendframework/zend-cache'
copyright: 'Copyright (c) 2005-2018 <a href="https://www.zend.com/">Zend Technologies USA Inc.</a>'
4 changes: 2 additions & 2 deletions src/Pattern/CaptureCache.php
Original file line number Diff line number Diff line change
@@ -297,7 +297,7 @@ protected function createDirectoryStructure($pathname)
ErrorHandler::start();

if ($perm === false) {
// build-in mkdir function is enough
// built-in mkdir function is enough

$umask = ($umask !== false) ? umask($umask) : false;
$res = mkdir($pathname, ($perm !== false) ? $perm : 0775, true);
@@ -318,7 +318,7 @@ protected function createDirectoryStructure($pathname)
throw new Exception\RuntimeException("chmod('{$pathname}', 0{$oct}) failed", 0, $err);
}
} else {
// build-in mkdir function sets permission together with current umask
// built-in mkdir function sets permission together with current umask
// which doesn't work well on multo threaded webservers
// -> create directories one by one and set permissions

4 changes: 2 additions & 2 deletions src/Pattern/PatternOptions.php
Original file line number Diff line number Diff line change
@@ -152,7 +152,7 @@ class PatternOptions extends AbstractOptions
public function __construct($options = null)
{
// disable file/directory permissions by default on windows systems
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
if (stripos(PHP_OS, 'WIN') === 0) {
$this->filePermission = false;
$this->dirPermission = false;
}
@@ -446,7 +446,7 @@ public function setFilePermission($filePermission)
);
} elseif ($filePermission & 0111) {
throw new Exception\InvalidArgumentException(
"Invalid file permission: Files shoudn't be executable"
"Invalid file permission: Files shouldn't be executable"
);
}
}
2 changes: 1 addition & 1 deletion src/Psr/CacheItemPool/CacheItemPoolDecorator.php
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ public function getItems(array $keys = [])

$keys = array_diff($keys, array_keys($items));

if (count($keys)) {
if ($keys) {
try {
$cacheItems = $this->storage->getItems($keys);
} catch (Exception\InvalidArgumentException $e) {
12 changes: 9 additions & 3 deletions src/Psr/SimpleCache/SimpleCacheDecorator.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @see https://github.com/zendframework/zend-cache for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @copyright Copyright (c) 2018-2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-cache/blob/master/LICENSE.md New BSD License
*/

@@ -113,7 +113,10 @@ public function set($key, $value, $ttl = null)

$options = $this->storage->getOptions();
$previousTtl = $options->getTtl();
$options->setTtl($ttl);

if ($ttl !== null) {
$options->setTtl($ttl);
}

try {
$result = $this->storage->setItem($key, $value);
@@ -213,7 +216,10 @@ public function setMultiple($values, $ttl = null)

$options = $this->storage->getOptions();
$previousTtl = $options->getTtl();
$options->setTtl($ttl);

if ($ttl !== null) {
$options->setTtl($ttl);
}

try {
$result = $this->storage->setItems($values);
6 changes: 2 additions & 4 deletions src/Storage/Adapter/Dba.php
Original file line number Diff line number Diff line change
@@ -220,7 +220,6 @@ public function clearByNamespace($namespace)
}

$prefix = $namespace . $this->getOptions()->getNamespaceSeparator();
$prefixl = strlen($prefix);
$result = true;

$this->_open();
@@ -230,7 +229,7 @@ public function clearByNamespace($namespace)
$recheck = false;
$internalKey = dba_firstkey($this->handle);
while ($internalKey !== false && $internalKey !== null) {
if (substr($internalKey, 0, $prefixl) === $prefix) {
if (strpos($internalKey, $prefix) === 0) {
$result = dba_delete($internalKey, $this->handle) && $result;
}

@@ -259,7 +258,6 @@ public function clearByPrefix($prefix)
$options = $this->getOptions();
$namespace = $options->getNamespace();
$prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator() . $prefix;
$prefixL = strlen($prefix);
$result = true;

$this->_open();
@@ -269,7 +267,7 @@ public function clearByPrefix($prefix)
$recheck = false;
$internalKey = dba_firstkey($this->handle);
while ($internalKey !== false && $internalKey !== null) {
if (substr($internalKey, 0, $prefixL) === $prefix) {
if (strpos($internalKey, $prefix) === 0) {
$result = dba_delete($internalKey, $this->handle) && $result;
$recheck = true;
}
4 changes: 2 additions & 2 deletions src/Storage/Adapter/ExtMongoDbResourceManager.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @see https://github.com/zendframework/zend-cache for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @copyright Copyright (c) 2018-2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-cache/blob/master/LICENSE.md New BSD License
*/

@@ -98,7 +98,7 @@ public function getResource($id)
}

$collection = $resource['client_instance']->selectCollection(
isset($resouce['db']) ? $resource['db'] : 'zend',
isset($resource['db']) ? $resource['db'] : 'zend',
isset($resource['collection']) ? $resource['collection'] : 'cache'
);
$collection->createIndex(['key' => 1]);
4 changes: 2 additions & 2 deletions src/Storage/Adapter/Filesystem.php
Original file line number Diff line number Diff line change
@@ -1451,7 +1451,7 @@ protected function prepareDirectoryStructure($file)
ErrorHandler::start();

if ($perm === false || $level == 1) {
// build-in mkdir function is enough
// built-in mkdir function is enough

$umask = ($umask !== false) ? umask($umask) : false;
$res = mkdir($pathname, ($perm !== false) ? $perm : 0775, true);
@@ -1480,7 +1480,7 @@ protected function prepareDirectoryStructure($file)
throw new Exception\RuntimeException("chmod('{$pathname}', 0{$oct}) failed", 0, $err);
}
} else {
// build-in mkdir function sets permission together with current umask
// built-in mkdir function sets permission together with current umask
// which doesn't work well on multo threaded webservers
// -> create directories one by one and set permissions

4 changes: 2 additions & 2 deletions src/Storage/Adapter/FilesystemOptions.php
Original file line number Diff line number Diff line change
@@ -119,7 +119,7 @@ class FilesystemOptions extends AdapterOptions
public function __construct($options = null)
{
// disable file/directory permissions by default on windows systems
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
if (stripos(PHP_OS, 'WIN') === 0) {
$this->filePermission = false;
$this->dirPermission = false;
}
@@ -322,7 +322,7 @@ public function setFilePermission($filePermission)
);
} elseif ($filePermission & 0111) {
throw new Exception\InvalidArgumentException(
"Invalid file permission: Cache files shoudn't be executable"
"Invalid file permission: Cache files shouldn't be executable"
);
}
}
2 changes: 1 addition & 1 deletion src/Storage/Adapter/MemcachedResourceManager.php
Original file line number Diff line number Diff line change
@@ -332,7 +332,7 @@ public function getLibOptions($id)
$reflection = new ReflectionClass('Memcached');
$constants = $reflection->getConstants();
foreach ($constants as $constName => $constValue) {
if (substr($constName, 0, 4) == 'OPT_') {
if (strpos($constName, 'OPT_') === 0) {
$libOptions[$constValue] = $resource->getOption($constValue);
}
}
3 changes: 1 addition & 2 deletions src/Storage/Adapter/Memory.php
Original file line number Diff line number Diff line change
@@ -203,10 +203,9 @@ public function clearByPrefix($prefix)
return true;
}

$prefixL = strlen($prefix);
$data = & $this->data[$ns];
foreach ($data as $key => & $item) {
if (substr($key, 0, $prefixL) === $prefix) {
if (strpos($key, $prefix) === 0) {
unset($data[$key]);
}
}
4 changes: 2 additions & 2 deletions src/Storage/Adapter/RedisResourceManager.php
Original file line number Diff line number Diff line change
@@ -299,7 +299,7 @@ protected function connect(array & $resource)
}

if (! $success) {
throw new Exception\RuntimeException('Could not estabilish connection with Redis instance');
throw new Exception\RuntimeException('Could not establish connection with Redis instance');
}

$resource['initialized'] = true;
@@ -492,7 +492,7 @@ public function getLibOptions($id)
$reflection = new ReflectionClass('Redis');
$constants = $reflection->getConstants();
foreach ($constants as $constName => $constValue) {
if (substr($constName, 0, 4) == 'OPT_') {
if (strpos($constName, 'OPT_') === 0) {
$libOptions[$constValue] = $resource['resource']->getOption($constValue);
}
}
3 changes: 1 addition & 2 deletions src/Storage/Adapter/Session.php
Original file line number Diff line number Diff line change
@@ -123,9 +123,8 @@ public function clearByPrefix($prefix)
}

$data = $cntr->offsetGet($ns);
$prefixL = strlen($prefix);
foreach ($data as $key => & $item) {
if (substr($key, 0, $prefixL) === $prefix) {
if (strpos($key, $prefix) === 0) {
unset($data[$key]);
}
}
2 changes: 1 addition & 1 deletion src/Storage/Capabilities.php
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ class Capabilities
protected $supportedDatatypes;

/**
* Supported metdata
* Supported metadata
*
* If it's NULL the capability isn't set and the getter
* returns the base capability or the default value.
84 changes: 81 additions & 3 deletions test/Psr/SimpleCache/SimpleCacheDecoratorTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @see https://github.com/zendframework/zend-cache for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @copyright Copyright (c) 2018-2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-cache/blob/master/LICENSE.md New BSD License
*/

@@ -46,6 +46,15 @@ class SimpleCacheDecoratorTest extends TestCase
'resource' => false,
];

/** @var AdapterOptions|ObjectProphecy */
private $options;

/** @var StorageInterface|ObjectProphecy */
private $storage;

/** @var SimpleCacheDecorator */
private $cache;

public function setUp()
{
$this->options = $this->prophesize(AdapterOptions::class);
@@ -57,9 +66,9 @@ public function setUp()
/**
* @param bool $staticTtl
* @param int $minTtl
* @return ObjectProphecy
*/
public function mockCapabilities(
ObjectProphecy $storage,
private function getMockCapabilities(
array $supportedDataTypes = null,
$staticTtl = true,
$minTtl = 60
@@ -69,6 +78,22 @@ public function mockCapabilities(
$capabilities->getSupportedDatatypes()->willReturn($supportedDataTypes);
$capabilities->getStaticTtl()->willReturn($staticTtl);
$capabilities->getMinTtl()->willReturn($minTtl);

return $capabilities;
}

/**
* @param bool $staticTtl
* @param int $minTtl
*/
public function mockCapabilities(
ObjectProphecy $storage,
array $supportedDataTypes = null,
$staticTtl = true,
$minTtl = 60
) {
$capabilities = $this->getMockCapabilities($supportedDataTypes, $staticTtl, $minTtl);

$storage->getCapabilities()->will([$capabilities, 'reveal']);
}

@@ -739,4 +764,57 @@ public function testHasReRaisesExceptionThrownByStorage()
$this->assertSame($exception, $e->getPrevious());
}
}

public function testUseTtlFromOptionsWhenNotProvidedOnSet()
{
$capabilities = $this->getMockCapabilities();

$storage = new TestAsset\TtlStorage(['ttl' => 20]);
$storage->setCapabilities($capabilities->reveal());
$cache = new SimpleCacheDecorator($storage);

$cache->set('foo', 'bar');
self::assertSame(20, $storage->ttl['foo']);
self::assertSame(20, $storage->getOptions()->getTtl());
}

public function testUseTtlFromOptionsWhenNotProvidedOnSetMultiple()
{
$capabilities = $this->getMockCapabilities();

$storage = new TestAsset\TtlStorage(['ttl' => 20]);
$storage->setCapabilities($capabilities->reveal());
$cache = new SimpleCacheDecorator($storage);

$cache->setMultiple(['foo' => 'bar', 'bar' => 'baz']);
self::assertSame(20, $storage->ttl['foo']);
self::assertSame(20, $storage->ttl['bar']);
self::assertSame(20, $storage->getOptions()->getTtl());
}

public function testUseTtlFromOptionsOnSetMocking()
{
$this->options->getTtl()->willReturn(40);
$this->options->setTtl(40)->will([$this->options, 'reveal']);

$this->options->setTtl(null)->shouldNotBeCalled();

$this->storage->getOptions()->will([$this->options, 'reveal']);
$this->storage->setItem('foo', 'bar')->willReturn(true);

self::assertTrue($this->cache->set('foo', 'bar'));
}

public function testUseTtlFromOptionsOnSetMultipleMocking()
{
$this->options->getTtl()->willReturn(40);
$this->options->setTtl(40)->will([$this->options, 'reveal']);

$this->options->setTtl(null)->shouldNotBeCalled();

$this->storage->getOptions()->will([$this->options, 'reveal']);
$this->storage->setItems(['foo' => 'bar', 'boo' => 'baz'])->willReturn([]);

self::assertTrue($this->cache->setMultiple(['foo' => 'bar', 'boo' => 'baz']));
}
}
46 changes: 46 additions & 0 deletions test/Psr/SimpleCache/TestAsset/TtlStorage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* @see https://github.com/zendframework/zend-cache for the canonical source repository
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-cache/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Cache\Psr\SimpleCache\TestAsset;

use Zend\Cache\Storage\Adapter;
use Zend\Cache\Storage\Capabilities;

class TtlStorage extends Adapter\AbstractAdapter
{
/** @var array */
private $data = [];

/** @var array */
public $ttl = [];

protected function internalGetItem(& $normalizedKey, & $success = null, & $casToken = null)
{
$success = isset($this->data[$normalizedKey]);

return $success ? $this->data[$normalizedKey] : null;
}

protected function internalSetItem(& $normalizedKey, & $value)
{
$this->ttl[$normalizedKey] = $this->getOptions()->getTtl();

$this->data[$normalizedKey] = $value;
return true;
}

protected function internalRemoveItem(& $normalizedKey)
{
unset($this->data[$normalizedKey]);
return true;
}

public function setCapabilities(Capabilities $capabilities)
{
$this->capabilities = $capabilities;
}
}
17 changes: 15 additions & 2 deletions test/Storage/Adapter/ExtMongoDbResourceManagerTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @see https://github.com/zendframework/zend-cache for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @copyright Copyright (c) 2018-2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-cache/blob/master/LICENSE.md New BSD License
*/

@@ -12,7 +12,6 @@
use PHPUnit\Framework\TestCase;
use stdClass;
use Zend\Cache\Exception;
use Zend\Cache\Storage\Adapter\ExtMongoDbOptions;
use Zend\Cache\Storage\Adapter\ExtMongoDbResourceManager;

/**
@@ -117,6 +116,20 @@ public function testGetResourceInitialized()
$this->assertSame($resource, $this->object->getResource($id));
}

public function testCorrectDatabaseResourceName()
{
$id = 'foo';

$resource = [
'db' => getenv('TESTS_ZEND_CACHE_EXTMONGODB_DATABASE'),
'server' => getenv('TESTS_ZEND_CACHE_EXTMONGODB_CONNECTSTRING'),
];

$this->object->setResource($id, $resource);

$this->assertSame($resource['db'], $this->object->getResource($id)->getDatabaseName());
}

public function testGetResourceNewResource()
{
$id = 'foo';