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
Mexthey opened this issue Jun 19, 2019 · 4 comments
Closed

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

Mexthey opened this issue Jun 19, 2019 · 4 comments
Labels
bug A bug report status: medium Medium

Comments

@Mexthey
Copy link

Mexthey 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
Copy link
Member

niden 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?

@Mexthey
Copy link
Author

Mexthey 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
Copy link
Member

niden commented Jun 23, 2019

@Kzmxewsy Thanks will check that.

@niden
Copy link
Member

niden commented Jun 26, 2019

Resolved in #14211

@niden niden closed this as completed Jun 26, 2019
@niden niden added bug A bug report status: medium Medium and removed Bug - Medium labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

2 participants