Code Monkey home page Code Monkey logo

zend-cache's Introduction

Logo

Welcome to the Zend Framework 3.0 Release!

RELEASE INFORMATION

Zend Framework 3.0.1dev

This is the first maintenance release for the Zend Framework 3 series.

DD MMM YYYY

UPDATES IN 3.0.1

Please see CHANGELOG.md.

SYSTEM REQUIREMENTS

Zend Framework 3 requires PHP 5.6 or later; we recommend using the latest PHP version whenever possible.

INSTALLATION

We no longer recommend installing this package directly. The package is a metapackage that aggregates all components (and/or integrations) originally shipped with Zend Framework; in most cases, you will want a subset, and these may be installed separately; see https://docs.zendframework.com/ for a list of available packages and installation instructions for each.

We recommend using either the zend-mvc skeleton application:

$ composer create-project zendframework/skeleton-application project

or the Expressive skeleton application:

$ composer create-project zendframework/zend-expressive-skeleton project

The primary use case for installing the entire framework is when upgrading from a version 2 release.

If you decide you still want to install the entire framework:

$ composer require zendframework/zendframework

GETTING STARTED

A great place to get up-to-speed quickly is the Zend Framework QuickStart.

The QuickStart covers some of the most commonly used components of ZF. Since Zend Framework is designed with a use-at-will architecture and components are loosely coupled, you can select and use only those components that are needed for your project.

MIGRATION

For detailed information on migration from v2 to v3, please read our Migration Guide.

COMPONENTS

This package is a metapackage aggregating the following components:

CONTRIBUTING

If you wish to contribute to Zend Framework, please read the CONTRIBUTING.md and CODE_OF_CONDUCT.md files.

QUESTIONS AND FEEDBACK

Online documentation can be found at https://docs.zendframework.com/. Questions that are not addressed in the manual should be directed to the relevant repository, as linked above.

If you find code in this release behaving in an unexpected manner or contrary to its documented behavior, please create an issue with the relevant repository, as linked above.

Reporting Potential Security Issues

If you have encountered a potential security vulnerability in Zend Framework, please report it to us at [email protected]. We will work with you to verify the vulnerability and patch it.

When reporting issues, please provide the following information:

  • Component(s) affected
  • A description indicating how to reproduce the issue
  • A summary of the security vulnerability and impact

We request that you contact us via the email address above and give the project contributors a chance to resolve the vulnerability and issue a new release prior to any public exposure; this helps protect Zend Framework users and provides them with a chance to upgrade and/or update in order to protect their applications.

For sensitive email communications, please use our PGP key.

LICENSE

The files in this archive are released under the Zend Framework license. You can find a copy of this license in LICENSE.md.

ACKNOWLEDGEMENTS

The Zend Framework team would like to thank all the contributors to the Zend Framework project; our corporate sponsor, Zend Technologies / Rogue Wave Software; and you, the Zend Framework user.

Please visit us sometime soon at http://framework.zend.com.

zend-cache's People

Contributors

akrabat avatar bakura10 avatar brettmc avatar cgmartin avatar dasprid avatar evandotpro avatar ezimuel avatar freeaqingme avatar jonathanmaron avatar koopzington avatar maks3w avatar marc-mabe avatar michalbundyra avatar micheh avatar mikaelkael avatar mwillbanks avatar ocramius avatar pdeszynski avatar prolic avatar ralphschindler avatar samsonasik avatar sgehrig avatar stefanotorresi avatar thinkscape avatar thomasvargiu avatar thomasweidner avatar vahid-sohrabloo avatar veewee avatar wdalmut avatar weierophinney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zend-cache's Issues

Discussion: APC vs APCU

About Zend\Cache\Storage\Adapter\Apc

Starting with PHP 7, APCU won't provide the apc_* fonction by default. So the test in __construct will pass, and later other methods will fail with undefined function.

For "legacy" branch

 $enabled = ini_get('apc.enabled') && function_exists('apc_store');

For current branch which requires PHP >= 5.5, as no APC version exists I think It could make sense to use APCU by default, and switch all call to apcu_* functions.

Another way could be to create an Zend\Cache\Storage\Adapter\Apcu adapter, and mark the previous as deprecated. But it will require code changes in all consumer of this library.

Comments ?

P.S. notice, for now, apcu 5.0.0-dev segfaults during the test suite.... under investigation.

PSR-6 wrapper?

Has anyone done any work on a PSR-6 wrapper for zend-cache? I know the PSR still in review, but it would be darn handy...

Broken Events v2 compatibility

I think this just can`t work:
https://github.com/zendframework/zend-cache/blob/master/src/Storage/Adapter/AbstractAdapter.php#L193
https://github.com/zendframework/zend-eventmanager/blob/release-2.6.2/src/EventManager.php#L57

BTW, I'm not offending, just complaining, with the v3 oncoming this backward compatibility issues got worse directly, into masters. You know I can`t be happy with things like that. Spending time finding BC breaks in the ZF2 instead of doing work for my clients. I really appreciate your work but this is sad for me that the ZF2 is going like this.

Fatal error storing objects in xcache adapter

Fatal error: xcache_set(): Objects cannot be stored in the variable cache. Use serialize before xcache_set in /Users/matt/www/httpd/zend-cache/src/Storage/Adapter/XCache.php on line 348

As the docs say:

Warning : At the moment, It is not possible to store resources, callbacks or objects using xcache_* functions.

Looks the adapter needs to have "object" => false in it's supportedDatatypes options and also throw an exception instead of fatal error. I'm using xcache 3.2.0.

BTW, xcache > 3.1.0 does support CLI, so there's no need to skip the tests for stuff like this. I'll do a PR.

Check Documentation For Other Things

Check docs for other problems

TLDR; Cast your eye over the documetation for any problems not covered in the other issues

Things slip through the net, so check the documentation for other problems that have been missed. Common other problems include

  • Bullet lists (should be single * then space at the start of line)
  • Inline code - should be marked by three backticks at start and finish
  • bookdown.json file is correctly formated and has the right escaping
  • Links between documentation using RST have been stripped
  • Any other RST has been removed correctly
  • Anything and everything not covered

If you end up fixing the same problem over and over, please ping Gary Hockin - we may be able to add bespoke issue for that problem, or fix in automated capacity

Memcached adapter store bug in internalSetItems method for PHP 7.0

There is a bug (may be it is a feature)

When I store multiple keys at once instead of storing values (for example int(0) ) it stores something like

i:0;

The reason is in https://github.com/zendframework/zend-cache/blob/master/src/Storage/Adapter/Memcached.php#L403

Code below fixes issue

$namespacedKeyValuePairs[$this->namespacePrefix . $normalizedKey] = $value;

It seems to me that it may be related to all other adapters cause all of them have the same code.

I could provide test if it is necessary.

Redis Adapter checks majorversion with version_compare but RedisResourceManager returns integer

The RedisResourceManager always returns integer as version information. Therefore, the check in Redis Adapter wont work as expected.

    /**
     * Get redis server version
     *
     * @param string $id
     * @return int
     * @throws Exception\RuntimeException
     */
    public function getMajorVersion($id)
    {
        // check resource id and initialize the resource
        $this->getResource($id);

        return (int) $this->resources[$id]['version'];
    }
            $redisVersion = $this->resourceManager->getMajorVersion($this->resourceId);

            // redis >= 2.8
            // The command 'pttl' returns -2 if the item does not exist
            // and -1 if the item has no associated expire
            if (version_compare($redisVersion, '2.8',  '>=')) {
                $pttl = $redis->pttl($this->namespacePrefix . $normalizedKey);
                if ($pttl <= -2) {
                    return false;
                }
                $metadata['ttl'] = ($pttl == -1) ? null : $pttl / 1000;

            // redis >= 2.6
            // The command 'pttl' returns -1 if the item does not exist or the item as no associated expire
            } elseif (version_compare($redisVersion, '2.6', '>=')) {
                $pttl = $redis->pttl($this->namespacePrefix . $normalizedKey);
                if ($pttl <= -1) {
                    if (!$this->internalHasItem($normalizedKey)) {
                        return false;
                    }
                    $metadata['ttl'] = null;
                } else {
                    $metadata['ttl'] = $pttl / 1000;
                }

            // redis >= 2
            // The command 'pttl' is not supported but 'ttl'
            // The command 'ttl' returns 0 if the item does not exist same as if the item is going to be expired
            // NOTE: In case of ttl=0 we return false because the item is going to be expired in a very near future
            //       and then doesn't exist any more
            } elseif (version_compare($redisVersion, '2', '>=')) {
                $ttl = $redis->ttl($this->namespacePrefix . $normalizedKey);
                if ($ttl <= -1) {
                    if (!$this->internalHasItem($normalizedKey)) {
                        return false;
                    }
                    $metadata['ttl'] = null;
                } else {
                    $metadata['ttl'] = $ttl;
                }

            // redis < 2
            // The commands 'pttl' and 'ttl' are not supported
            // but item existence have to be checked
            } elseif (!$this->internalHasItem($normalizedKey)) {
                return false;
            }

Add storage adapter for YAC

An extreme fast shared memory cache extension YAC.
It's still in beta and it's not sure if this extension ever reaches it's beta state as it doesn't have a locking mechanism which leads a possibility to retrieve wrong data.

However it seems like this extension is already very popular and alternatives like APCu are still in beta, too.

Zend\Cache clearExpired - getMTime(): stat failed

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7467
User: @startef
Created On: 2015-04-28T23:31:13Z
Updated At: 2015-11-06T22:14:14Z
Body
Hello,

I recently encountered an old problem that was first described and fixed here: zendframework/zendframework#6048

On my more busy projects the logs get filled up with

PHP Fatal error: Uncaught exception 'RuntimeException' with message 'SplFileInfo::getMTime(): stat failed for .../some/dir/filename.dat' in .../some/dir/zendframework/zend-cache/Zend/Cache/Storage/Adapter/Filesystem.php:153

The ExceptionHandler should have taken care of it actually, but somehow it doesn't anymore.

startef

Edit: Just noticed, it is not only the getMTime(). It also shows exceptions for unlink(), probably for the same reason of concurrent requests.

Edit2: PHP-Version is 5.5.22


Comment

User: @startef
Created On: 2015-08-17T10:20:16Z
Updated At: 2015-08-17T10:20:16Z
Body
A temporary solution was posted at heiseonline/shariff-backend-php#22


Add APCu adapter as feature replacement for Apc

As of the old PHP extension APC seems inactive and doesn't compile with PHP-5.6 / PHP-7 (PHP-5.4 should work but PHP-5.5 not tested) we can drop the adapter for it.

In fact the APC extension is inactive because of the PHP opcache and the possibility to store user data in the cache has been moved to APCu long time ago.

APC and APCu is nearly compatible on storing user data but in some cases it's not. The differences are already part of the Apc adapter.

To simplify the adapter a little bit and because it's no longer possible to use the old APC extension with the minimal required PHP version it makes sense to completely drop support for it.

Renaming the adapter from Apc to Apcu:
If I only take a look what the optimal way would look like it would make sense to also rename the Apc adapter to Apcu. With a deeper look the there are two cases where it could make confusion.

  • The APCu extension comes with a BC safe version (the version that the current adapter supports only)
    • Even if it's compiled with BC to APC all APCu functionalities are available
    • -> from this POV it's fine
  • HHVM comes with APC support for the old APC extension.
    • Does someone now if HHVM also supports APCu?

@weierophinney @ezimuel @Ocramius @Maks3w Thoughts?

Zend Data Cache: APC compatibility broken

The Zend Data Cache comes with a compatibility layer for APC but the APC adapter doesn't work with it:

curl -sS -v 'http://localhost/test-zend-cache.php'
* About to connect() to localhost port 80 (#0)
*   Trying ::1...
* Connected to localhost (::1) port 80 (#0)
> GET /test-zend-cache.php HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Wed, 17 Feb 2016 21:08:54 GMT
< Server: Apache/2.4.6 (CentOS) PHP/5.6.17
< X-Powered-By: PHP/5.6.15 ZendServer/8.5.2
< ZRay-ID: 0@3936@1455741553@0
< Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/
< Content-Length: 81
< Content-Type: text/html; charset=UTF-8
< 
.............E.......E..EE..E.E.E.....E......E.FF.F.FF......SEEE. 65 / 72 ( 90%)

I currently don't get the full result. Could be a segmentation fault somewhere but it's a bit more work as the Zend Data Cache doesn't run in CLI and this bug is not very impotent.

-> For now if you are using the Zend Data Cache than please use one of the ZendServer[Disk|Shm] adapters.

How to overwrite adapter config?

I have a cache configuration array (defined in some module config file) that is handed over to StorageFactory::factory():

array(
    'adapter' => array(
        'name' => 'filesystem',
        'options' => array(
            'cache_dir' => 'data/cache/navigation',
            'dir_level' => 0,
            'namespace' => '',
        ),
),

Now if I want to use another adapter on my local development machine, I insert the following code into my local.php

array(
    'adapter' => array(
        'name' => 'blackhole',
        ),
),

This overwrites the adapter name, but does not work: All the other, already given, options are being pushed to the blackhole adapter, but the corresponding methods like setCacheDir() don't exist there.
(The BlackHole adapter ist just an example, the problem would be the same if you had configured Memcache but want to use Filecache locally.)

So how do you correctly define adapters together with their options in your global config files so they still can be overwritten in local config files?

Thanks in advance, Estigy

Registering own plugins with their factories

How can I register my own plugins that are using a factory? Im using the zend-mvc.
Example for a view-helper:

return [
  'view_helpers' => [
    'factories' => [
      'myViewHelper' => MyViewHelperFactory::class,
    ],
  ],
];

If I register my plugin factory in the normal service_manager it just defaults back to the invokable factory. But my plugin has a dependency that should be injected via the constructor...
I've browsed the code but didnt find anything to make it work. Is this currently possible?

Versions in use:

zendframework/zend-cache                     2.7.1
zendframework/zend-config                    2.6.0
zendframework/zend-eventmanager              3.0.1
zendframework/zend-modulemanager             2.7.2              
zendframework/zend-mvc                       3.0.3              
zendframework/zend-servicemanager            3.1.1              

Filesystem Adapter

Hi, the setItem method on the Filesystem adapter allows a mixed as value. However internally when blocking is enabled, it will try to do a fwrite which requires the data to be a string. Shouldn't Filesystem adapter require data as a string also? or at least serialize the value if it is not a string before attempting to fwrite.

clearByTags in Filesystem adapter crashes when .tag file deleted during GlobIterator loop

Hi,

we see the following error when using Filesystem storage adapter and deleting a large set of object from cache with clearByTags() method.

// when file_locking is off in File Zend/Cache/Storage/Adapter/Filesystem.php in line 1363
file_get_contents(my_cache_dir/my_cached_object_4711.tag): failed to open stream: No such file or directory
// when file_locking is on in File Zend/Cache/Storage/Adapter/Filesystem.php in line 1327
fopen(my_cache_dir/my_cached_object_4711.tag): failed to open stream: No such file or directory

It is not that easy to reproduce but occurs as follows:

  • the GlobIterator in clearByTags() looks for all .tag files which holds the cached item tags information
  • while looping through these items, another process deletes one item (and its .tag file) which is also prior found by the GlobIterator
  • clearByTags triggers an error at $this->getFileContent($pathname) because fopen() or file_get_contents try to open a non existing file (not existing anymore)

Should be simple be avoided by adding

if (!file_exists($file)) { // or !$glob->valid()?
    continue;
}

to the foreach loop in clearByTags(), but is this right?

I also can submit a PR, but until now i do not have found a way to reproduce for a unit test

cheers

Check All Headers In Documentation

Check headers are correct

TLDR; Headers should use the #, ## etc to format different levels of headers, and not be underlines using ===== or ``-----`, or be psuedo header using bold

Check all headers on the documentation - headers should use the hash style of declaration rather then be underlined with equals or dashes. The more hashes, the more of a subheading. Eg:

  • # is equal to <h1>
  • ## is equal to <h2>
  • ### is equal to <h3>
  • #### is equal to <h4>
  • ##### is equal to <h5>

Headings should be appropriate for their level in the documentation.

Psuedo headers using bold tags ** should be replaced with appropriate level of heading tag.

Cleanup capabilities

Some of the current defined capabilities are very hard to understand/useless and I would like to define some of them.

minTtl
This defines the minimum supported TTL which is clear but only a handful people knows that this also defines the general TTL support.

  • 0 means TTL is supported

  • 0 means TTL is not supported and all other TTL related capabilities can be ignored

There is no adapter having another value than 0 or 1 so this can be renamed to ttlSupported with bool.

-> minTtl needs to be still available for BC reasons until the next major but can be marked deprecated.

staticTtl
This defines how the expiration time will be calculated which is not a meaningful description.

  • true means the expiration time will be calculated on read using the last-modification-time of the item, the current time and the current TTL option
  • false means the expiration time will be calculated using the current TTL and the current time. It will be stored together with the item

Thoughts for better names ?

expiredRead
There was the idea that it is possible to read an expired item by setting changing the TTL (like to 0 = infinitive) but this only works with staticTtl=true to make it possible using an expired item in cases regeneration breaks (like on failed DB connection).

This is a useless capability because changing the TTL to something else automatically changes the expiration time of all stored items if staticTtl=true which means in case for infinity the item is no longer expired. -> Bam the item is no longer expired but this capability is for reading expired items and the nature of staticTtl already defines this behavior.

-> I would like to deprecate this capability and remove it in the next major version.

@kynx @Maks3w @Ocramius @ezimuel Thoughts ?

Check All Headers In Documentation

Check headers are correct

TLDR; Headers should use the #, ## etc to format different levels of headers, and not be underlines using ===== or ``-----`, or be psuedo header using bold

Check all headers on the documentation - headers should use the hash style of declaration rather then be underlined with equals or dashes. The more hashes, the more of a subheading. Eg:

  • # is equal to <h1>
  • ## is equal to <h2>
  • ### is equal to <h3>
  • #### is equal to <h4>
  • ##### is equal to <h5>

Headings should be appropriate for their level in the documentation.

Psuedo headers using bold tags ** should be replaced with appropriate level of heading tag.

Redis Cache Adapter fails when using socket

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7601
User: @Moring
Created On: 2015-07-01T22:35:41Z
Updated At: 2015-11-06T22:06:36Z
Body
Bit of edge case:

Redis is attached to ZF2 cache via socket.

Doctrine redis cache via DoctrineModule\Cache\ZendStorageCache

It will fail intermittently (and always on Doctrine query error).

Error: 'Could not estabilish connection with Redis instance'

Does not occur with port connection.

If: $redis->getTotalSpace() called against ZF2 Redis Cache Adapter before wrapped in DoctrineModule\Cache\ZendStorageCache -- no error.


SharedEventManager - first argument should be either a string or an integer

After updating from zendframework/zend-cache (2.5.3) to (2.6.0) I got error

array_key_exists(): The first argument should be either a string or an integer
in File: .../vendor/zendframework/zend-eventmanager/src/SharedEventManager.php Line: 153

151:        public function getListeners($id, $event)
152:        {
153:            if (!array_key_exists($id, $this->identifiers)) {
154:                return false;
155:            }
156:            return $this->identifiers[$id]->getListeners($event);
157:        }

with arguments:

$key    
Zend\EventManager\SharedEventManager(1) ▼ {
   identifiers protected => array(0) 
}
$search 
array(4) ▼ {
   "Zend\Mvc\Application" => Zend\EventManager\EventManager(4) ▼ {
      events protected => array(1) ▼ {
         bootstrap => Zend\Stdlib\PriorityQueue(3) { ... }
      }
      eventClass protected => "Zend\EventManager\Event" (23)
      identifiers protected => array(1) ▼ [
         0 => "Zend\Mvc\Application" (20)
      ]
      sharedManager protected => NULL
   }
   doctrine => Zend\EventManager\EventManager(4) ▼ {
      events protected => array(1) ▼ {
         "loadCli.post" => Zend\Stdlib\PriorityQueue(3) { ... }
      }
      eventClass protected => "Zend\EventManager\Event" (23)
      identifiers protected => array(1) ▼ [
         0 => "doctrine" (8)
      ]
      sharedManager protected => NULL
   }
   "Zend\Stdlib\DispatchableInterface" => Zend\EventManager\EventManager(4) ▼ {
      events protected => array(1) ▼ {
         dispatch => Zend\Stdlib\PriorityQueue(3) { ... }
      }
      eventClass protected => "Zend\EventManager\Event" (23)
      identifiers protected => array(1) ▼ [
         0 => "Zend\Stdlib\DispatchableInterface" (33)
      ]
      sharedManager protected => NULL
   }
   profiler => Zend\EventManager\EventManager(4) ▼ {
      events protected => array(1) ▼ {
         collected => Zend\Stdlib\PriorityQueue(3) { ... }
      }
      eventClass protected => "Zend\EventManager\Event" (23)
      identifiers protected => array(1) ▼ [
         0 => "profiler" (8)
      ]
      sharedManager protected => NULL
   }
}

Can someone help? -_-

[3.0] Cache

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7211
User: @marc-mabe
Created On: 2015-02-12T19:03:23Z
Updated At: 2015-11-06T20:22:37Z
Body
I would like to "fix" some weird logic from cache component.

  • Reduce arguments by reference
  • Move / Remove resource manager logic
    • the the cache storage adapter directly receives the basic resource (instances of Memcache, Memcached, MongoClient, Redis, MongoCollection, ...)
    • Where to move this logic to or should that be removed and leaving it up to the user?

Thoughts ?

ping @Ocramius @weierophinney


Prototype fixing #6381: Order of resource based adapter options may cause Exception

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7205
User: @marc-mabe
Created On: 2015-02-11T19:43:42Z
Updated At: 2015-02-25T18:26:10Z
Body
This is a prototype!!!!

This would be duplicated in all Options classes requiring some ordering of options.

@Ocramius @weierophinney In my opinion the issue #6381 should be marked as won't fixed as the options will be applied in the order they are defined. This behavior should be documented but not changed into a adapter defined ordering like this prototype. Additionally this prototype shows it's more error prone than the current behavior and would be needed to be document3ed for each adapter what the defined order would resulting in other WTF moments.


Comment

User: @weierophinney
Created On: 2015-02-19T21:16:47Z
Updated At: 2015-02-19T21:16:47Z
Body
My feeling is that this shouldn't be abstracted at all. If options need to be set in a particular order, then each options class should implement this functionality accordingly, instead of relying on the parent. This is particularly salient considering you've re-implemented most of the logic of Zend\Stdlib\AbstractOptions::setFromArray() already; why delegate to the parent at all?

Instead, go through the options in the order in which they should be applied and set them on the instance directly.


Redis sIsMember or sContains?

Maybe there is a new way of doing this that I am unaware of but I don't see why this would not be a feature within the redis adapter?

Example:

$redis->sAdd('key1' , 'member1');
$redis->sAdd('key1' , 'member2');
$redis->sAdd('key1' , 'member3'); /* 'key1' => {'member1', 'member2', 'member3'}*/

$redis->sIsMember('key1', 'member1'); /* TRUE */
$redis->sIsMember('key1', 'memberX'); /* FALSE */

plugin by the name "exception_handler" was not found

When trying to use zend-cache downloaded separately via Composer (under Windows 7, fwiw), the following exception is thrown:

A plugin by the name "exception_handler" was not found in the plugin manager Zend\Cache\Storage\PluginManager

The relevant part of the stack trace:

0 ...\vendor\zendframework\zend-cache\src\StorageFactory.php(203): Zend\ServiceManager\AbstractPluginManager->get('exception_handl...')

composer.json used to download the package:

{
    "name": "test",
    "require": {
        "zendframework/zend-cache": "^2.5"
    }
}

In case of using zend-cache from ZF downloaded entirely ("zendframework/zendframework": "^2.5"), the issue is not reproduced.

Thanks.

Redis capability to add diverse TTL

Currently, it seems the capability to set a TTL on an item in Redis is on instantiation as a set configuration value.

As redis has the ability to be used as a database, or cache. I believe the ability to set the TTL on item creation should be implemented.

For example in addItem(s) a new parameter $ttl = null could be appended on and default to the base $options->getTtl()

protected function internalSetItem(& $normalizedKey, & $value, $tt = NULL)
    {
        $redis   = $this->getRedisResource();
        $options = $this->getOptions();
        $ttl     = $ttl ?: $options->getTtl();

        ...

This will allow the ability to diversify the Redis adapter as a database AND cache storage, instead of one OR the other.

MongoDB auto-expire

MongoDB will auto-expire documents if an index is set on the expiration field:

db.cache.ensureIndex( { "expires": 1 }, { expireAfterSeconds: 3600 } )

It doesn't seem like this cache adapter supports this though. What's the best way to implement this? I was thinking that perhaps the internalSetItem() method could get the current indexes, and add the index if it doesn't exist.

Component split

I would like to get your opinions about splitting zend-cache into different components.
The reason for that is simply a testing and dependency hell.

  • It's not possible to define a required extension in composer.json so all adapters have to manually check if the current environment is matching the requirements
  • Testing against all adapters is a nightmare and takes very long.
    • The travis.yml file al already very complex but it still doesn't test all common cases.
    • Some extensions are missing or not 100% compatible for PHP-7 which makes things here more complicated.
    • Doesn't test against different (most common) extension versions
    • Nearly impossible to run tests for ZendServer adapters
  • another reason is that normally you only need 1 or 2 adapters but that's not very important as zend-cache doesn't install so many files per adapter.

In my opinion it makes sense to split parts into it's own repository as long as the part requires a non standard extension or another currently optional dependency.

Thoughts ?

This is a structure how this could look like:

zendframework/zend-cache

  • Exceptions
  • Patterns
  • Service
  • Factories
  • Storage Interfaces
  • Storage Plugins
    • all except the Serializer plugin
  • Storage Adapters
    • BlackHole
    • Filesystem
    • Memory

zendframework/zend-cache-serializer

  • adds the serializer storage plugin which requires zend-serializer

zendframework/zend-cache-apc

  • adds the Apc storage adapter requires the apc extension (or compatible extension)

zendframework/zend-cache-apcu

  • adds the Apcu storage adapter requires the apcu extension

zendframework/zend-cache-dba

  • adds the Dba storage adapter requires the dba extension

zendframework/zend-cache-memcache

  • adds the Memcache storage adapter requires the memcache extension

zendframework/zend-cache-memcached

  • adds the Memcached storage adapter requires the memcached extension

zendframework/zend-cache-mongo

  • adds the Mongo storage adapter requires the mongo extension
  • It's currently the MongoDb adapter but there is also another extension called mongodb

zendframework/zend-cache-redis

  • adds the Redis storage adapter requires the redis extension

zendframework/zend-cache-session

  • adds the Session storage adapter requires the zend-session

zendframework/zend-cache-wincache

  • adds the WinCache storage adapter requires the wincache extension

zendframework/zend-cache-xcache

  • adds the XCache storage adapter requires the xcache extension

zendframework/zend-cache-zendserver

  • adds the ZendDataCacheDisk and ZendDataCacheShm storage adapter requires the zend data cache extension
  • This is currently called ZendServerDisk / ZendServerShm because the extension is part of Zend Server

serializer not found

no matter what i do i get

 Class 'Zend\Serializer\Serializer' not found

this is with any version ^2.7

Check All Headers In Documentation

Check headers are correct

TLDR; Headers should use the #, ## etc to format different levels of headers, and not be underlines using ===== or ``-----`, or be psuedo header using bold

Check all headers on the documentation - headers should use the hash style of declaration rather then be underlined with equals or dashes. The more hashes, the more of a subheading. Eg:

  • # is equal to <h1>
  • ## is equal to <h2>
  • ### is equal to <h3>
  • #### is equal to <h4>
  • ##### is equal to <h5>

Headings should be appropriate for their level in the documentation.

Psuedo headers using bold tags ** should be replaced with appropriate level of heading tag.

Check Documentation Tables

Check the tables in a document

TLDR; All tables should be in the format of GHFM using | and - as horizontal and vertical separators respectively

Check all tables are in the correct format. Please don't use leading and trailing | - more information on github flavoured markdown tables can be found here.

2.4.8 tag missing

So, having "zendframework/zend-cache": "~2.4.0" in composer.json won't update to 2.4.8 whic include the security fix for ZF2015-07

Check Documentation Code Blocks

Check code blocks are correct

TLDR; Check in all files that codeblocks are correct, in PSR-2 format and have PHP syntax highlighting applied.

Code blocks should be in the following format...

```php
 'ZEND-FRAMEWORK');

// No required options
$rendererOptions = array();
$renderer = Barcode::factory(
    'code39', 'image', $barcodeOptions, $rendererOptions
);

```

Note the three backticks then php in the opening fence, and the closing fence is just three backticks. It's common for the opening backticks to have no code type, or something like source.

Code should also have been automatically formatted into PSR-2 format, but sometimes these slip through the net.

Check For Blockquotes In Docs

Check the document for bad blockquoutes

TLDR; Check blockquotes are formatted correctly using > and check headings in blockquotes are using ###

Blockquotes are donated by a single greater than character and then a space. Make sure all the blockquotes in every doc file are correctly formatted. Headings in blockquotes should use ### and not bold.

Any paragraph spacing in blockquotes should be marked using a single greater than, then a space.

array_key_exists() error when updating from 2.5.3 to 2.6

Error:

array_key_exists(): The first argument should be either a string or an integer

Calling:

$config['cache'] = 'adapter' => [
    'name' => 'memcached',
            'options' => [
                'servers' => [
                    [
                        'host' => 'localhost',
                        'port' => '11211',
                    ],
                ],
            ],
        ];

$cache = StorageFactory::factory($config['cache']);

Stack:

Whoops\Exception\ErrorException: array_key_exists(): The first argument should be either a string or an integer
  File "/Users/user/dev/myapp/public/index.php", line 10, in null
    $app->run();
  File "/Users/user/dev/myapp/vendor/zendframework/zend-mvc/src/Application.php", line 314, in run
    $result = $events->trigger(MvcEvent::EVENT_DISPATCH, $event, $shortCircuit);
  File "/Users/user/dev/myapp/vendor/zendframework/zend-eventmanager/src/EventManager.php", line 214, in trigger
    return $this->triggerListeners($event, $e, $callback);
  File "/Users/user/dev/myapp/vendor/zendframework/zend-eventmanager/src/EventManager.php", line 490, in triggerListeners
    $responses->push(call_user_func($listenerCallback, $e));
  File "/Users/user/dev/myapp/vendor/zendframework/zend-mvc/src/DispatchListener.php", line 93, in onDispatch
    $return = $controller->dispatch($request, $response);
  File "/Users/user/dev/myapp/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php", line 118, in dispatch
    });
  File "/Users/user/dev/myapp/vendor/zendframework/zend-eventmanager/src/EventManager.php", line 214, in trigger
    return $this->triggerListeners($event, $e, $callback);
  File "/Users/user/dev/myapp/vendor/zendframework/zend-eventmanager/src/EventManager.php", line 490, in triggerListeners
    $responses->push(call_user_func($listenerCallback, $e));
  File "/Users/user/dev/myapp/module/myapp/src/Controller/CliController.php", line 44, in onDispatch
    $viewModel = parent::onDispatch($e);
  File "/Users/user/dev/myapp/vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php", line 82, in onDispatch
    $actionResponse = $this->$method();
  File "/Users/user/dev/myapp/module/MyModule/src/Controller/Cli/MyModuleController.php", line 29, in importAction
    $cache = $this->getCache();
  File "/Users/user/dev/myapp/module/MyModule/src/Controller/Cli/MyModuleTrait.php", line 24, in getCache
    return StorageFactory::factory($config['cache']);
  File "/Users/user/dev/myapp/vendor/zendframework/zend-cache/src/StorageFactory.php", line 72, in factory
    $adapter = static::adapterFactory((string) $adapterName, $adapterOptions);
  File "/Users/user/dev/myapp/vendor/zendframework/zend-cache/src/StorageFactory.php", line 149, in adapterFactory
    $adapter->setOptions($options);
  File "/Users/user/dev/myapp/vendor/zendframework/zend-cache/src/Storage/Adapter/Memcached.php", line 131, in setOptions
    return parent::setOptions($options);
  File "/Users/user/dev/myapp/vendor/zendframework/zend-cache/src/Storage/Adapter/AbstractAdapter.php", line 130, in setOptions
    $this->getEventManager()->triggerEvent($event);
  File "/Users/user/dev/myapp/vendor/zendframework/zend-eventmanager/src/EventManager.php", line 251, in triggerEvent
    return $this->triggerListeners($event->getName(), $event);
  File "/Users/user/dev/myapp/vendor/zendframework/zend-eventmanager/src/EventManager.php", line 469, in triggerListeners
    $sharedListeners         = $this->getSharedListeners($event);
  File "/Users/user/dev/myapp/vendor/zendframework/zend-eventmanager/src/EventManager.php", line 530, in getSharedListeners
    if (!$listeners = $sharedManager->getListeners($id, $event)) {
  File "/Users/user/dev/myapp/vendor/zendframework/zend-eventmanager/src/SharedEventManager.php", line 153, in getListeners
    if (!array_key_exists($id, $this->identifiers)) {
  File "/Users/user/dev/myapp/vendor/zendframework/zend-eventmanager/src/SharedEventManager.php", line 153, in handleError
    if (!array_key_exists($id, $this->identifiers)) {

Idea: add getItemWithCallback method

Implementation could looks like

function getItemWithCallback($key, $callback) {
   $item = $this->getItem($key);
   if ($item === false) {
       $item = $callback($key);
       $this->setItem($key, $item);
   }
   return $item;
}

And with APCu 5.1, this can be override to use new "apcu_entry" API which will manage a lock to avoid bad run race condition, and a single execution of the callback.

RedisResourceManager breaks if being configured via StorageCacheAbstractServiceFactory/array and server key isn't first in options array

I take the example from the docs to demonstrate the problem:

'caches' => array( 'Cache\Transient' => array( 'adapter' => 'redis', 'ttl' => 3600, 'options' => array( 'server' => array( 'host'=>'localhost', 'port' => 6379, 'timeout' => 2.5, ), 'database' => 5, 'password' => '', ), 'plugins' => array( 'exception_handler' => array( 'throw_exceptions' => false, ), 'serializer', ), ), ),

The relevant part is the options array.

'options' => array( 'server' => array( 'host'=>'localhost', 'port' => 6379, 'timeout' => 2.5, ), 'database' => 0, 'password' => '', ),
would work, but for example
'options' => array( 'database' => 0, 'server' => array( 'host'=>'localhost', 'port' => 6379, 'timeout' => 2.5, ), 'password' => '', ),
wouldn't.

All the setters in RedisResourceManager look if the id is already initialised, if not, every setter calls setResource with only his own parameter.
setResource merges this with the default array, which has empty array for the server key. At the end of the function setResource always calls normalizeServer, which checks if key host is set and throws an exception, if it's not.
As it is now, the code fails for every initialisation, where server key isn't the first inside the options array, because an exception is thrown.

I'm not making own fix via pull request, because this should be a design decision.

This problem also exists in the LTS 2.4 branch in exactly the same way.

Travis: APC tests not running

I found out two reasons:

  1. Installing the APCu extension fails on PHP < 7 as the last beta supports PHP 7 only
    echo "yes\nno\n" | pecl -d preferred_state=beta install apcu || return 0
  2. It looks like the extension will not be automatically enabled by pecl

[ZF3] Split out resource factories / manager

One of the most confusion part of the current cache component is the usage of resource manager.
The resource managers are used to instantiate resources (like an instance of Memcache/d) and to share the same resources over different instances of the fitting interface. Sharing resource is required to not open a new resource (like a network connection) to the same thing only to be able to use different storage instances with different options (like namespace / TTL).

In my opinion the cache adapters should not contain so much complexity and I would like to remove this functionality and simply let inject the resources into the adapters if required.

But where move this functionality to?

  • Should this be part of another component like zend-servicemanager?
  • Should this be done completely by the user?

Related:

@weierophinney @ezimuel @Maks3w @Ocramius Thoughts?

Redis#getCapabilities error when not yet initialized

Situation
$redisCache = \Zend\Cache\StorageFactory::factory([
    'adapter' => [
        'name' => 'redis'
    ],
    'options' => [
        'server' => ['host' => 'localhost'],
    ]
]);
$cap = $redisCache->getCapabilities();
Result

Fatal error: Call to a member function getMajorVersion() on null in zendframework\zend-cache\src\Storage\Adapter\Redis.php on line 449

Expected

$cap instanceof \Zend\Cache\Storage\Capabilities

Compatibility issues with ZF3

Hello everyone.

I'm currently running through the process of migrating my ZF2 application to ZF3. I got stuck in a nasty issue which I cannot get around.

Essentially, when Memcached is called for the first time during the application bootstrap phase, the extension throws a response error code (@see http://php.net/manual/en/memcached.getresultcode.php) RES_HOST_LOOKUP_FAILURE.

However, if I simply try to create a server and connect, set and get a key via php -a, I'm able to do it. Do we have support for ZF3 here? Or for Memcached?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.