Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\Phalcon\Cache\Backend\File -> queryKeys #14190

Closed
Kzmxewsy opened this issue Jun 19, 2019 · 4 comments

Comments

@Kzmxewsy
Copy link

commented Jun 19, 2019

Hello, strictly speaking, I don't know if this is a bug, because It's easy to fix, is it designed to be like this originally?

minimal script to reproduce the issue

    public function reproduceAction()
    {
        $cache = new \Phalcon\Cache\Backend\File(
            new \Phalcon\Cache\Frontend\Data([
                "lifetime" => $this->config->cache->lifetime,
            ]), [
                "prefix" => $this->config->cache->prefix,
                "cacheDir" => $this->config->cache->dir,
            ]
        );

        $prefix = 'my-prefix';
        foreach (range('a', 'z') as $key => $value) {
            $key = $prefix . '.' . $key;
            $cache->save($key, $value);
        }

        $allKeys = $cache->queryKeys($prefix);
        print_r($allKeys);

        $fail = 0;
        if ($allKeys) {
            foreach ($allKeys as $delKey) {
                // If {$this->config->cache->prefix } is not empty 
               // It does't work,because the result of queryKeys is contained prefix
                $cache->delete($delKey) || $fail++;
            }
        }
        print_r($fail);
        exit;
    }

Details

  • Phalcon version: (php --ri phalcon) v3.4.3
  • PHP Version: (php -v) PHP 7.2.17 x64 TS
  • Operating System: win
  • Installation type: download dll
  • Zephir version (if any):
  • Server: Nginx
  • Other related info (Database, table schema): Postgresql
@niden

This comment has been minimized.

Copy link
Member

commented Jun 21, 2019

@Kzmxewsy Not sure why this was designed this way but the whole cache namespace has been refactored to implement PSR-16. Can you test your code with v4?

@Kzmxewsy

This comment has been minimized.

Copy link
Author

commented Jun 23, 2019

@Kzmxewsy Not sure why this was designed this way but the whole cache namespace has been refactored to implement PSR-16. Can you test your code with v4?

@niden I have tested it with v4.0.0-alpha.5,But I am not familiar with v4, the code is below

function reproduce()
{
    $cache = new \Phalcon\Cache\Adapter\Stream(
        new Phalcon\Storage\SerializerFactory([
            "lifetime" => 86400,
        ]), [
            "prefix" => 'test',
            "cacheDir" => 'cache',
        ]
    );

    $prefix = 'my-prefix';
    foreach (range('a', 'z') as $key => $value) {
        $key = $prefix . '.' . $key;
        $cache->set($key, $value);
    }

    $allKeys = $cache->getKeys($prefix);
    print_r($allKeys);

    $fail = 0;
    if ($allKeys) {
        foreach ($allKeys as $delKey) {
            // It does't work,because the result of queryKeys is contained prefix=>test
            $cache->delete($delKey) || $fail++;
        }
    }
    print_r($fail);
    exit;
}

Although the cached file structure is different, the result is the same as v3.

@niden

This comment has been minimized.

Copy link
Member

commented Jun 23, 2019

@Kzmxewsy Thanks will check that.

@niden niden added this to To do in 4.0 Release via automation Jun 23, 2019

ekmst added a commit to ekmst/cphalcon that referenced this issue Jun 26, 2019

@ekmst ekmst referenced this issue Jun 26, 2019

Merged

Fixed #14190: Cache\Backend\File -> queryKeys #14211

4 of 5 tasks complete
@niden

This comment has been minimized.

Copy link
Member

commented Jun 26, 2019

Resolved in #14211

@niden niden closed this Jun 26, 2019

4.0 Release automation moved this from To do to Done Jun 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
2 participants
You can’t perform that action at this time.