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

[BUG]: Phalcon v5.0.0-alpha.2 - whats wrong with models cache? #15471

Closed
borisdelev opened this issue May 6, 2021 · 12 comments · Fixed by #15478
Closed

[BUG]: Phalcon v5.0.0-alpha.2 - whats wrong with models cache? #15471

borisdelev opened this issue May 6, 2021 · 12 comments · Fixed by #15478
Assignees
Labels
5.0 The issues we want to solve in the 5.0 release breaks bc Functionality that breaks Backwards Compatibility bug A bug report documentation Documentation required status: medium Medium

Comments

@borisdelev
Copy link
Contributor

Describe the bug
I try to migrate to Phalcon v.5 (php8) or just still try it with my project- need to be sure they will work fine with next releases. And yes, they works almost fine... except something with cache stuff. The error i get is:
Fatal error: Uncaught TypeError: Phalcon\Mvc\Model\Resultset\Simple::__construct(): Argument #4 ($cache) must be of type ?Phalcon\Cache\Adapter\AdapterInterface, Phalcon\Cache given in v1\modules\client\controllers\ControllerBase.php on line 33

So, in this line i have:

        $articles = \Models\Articles::find([
            'conditions' => 'is_global=1',
            'cache' => [
                'key' => 'global-articles'
            ]
        ]);

... and see is something related with models cache service. Its init like that:

/*
 * Set the models cache service
 */
$di->set('modelsCache', function () use ($config) {
    $lifetime = 60 * 60 * 24 * 7; // 7 days
    if ($config->development) {
        $lifetime = 60; // 1 min
    }
    
    // Create folder if did not exists
    $folder = BASE_PATH . 'cache/queries/';

    $serializerFactory = new \Phalcon\Storage\SerializerFactory();
    $adapter = new \Phalcon\Cache\Adapter\Stream($serializerFactory, [
        'storageDir' => $folder,
        'lifetime' => $lifetime
    ]);
    
    $cache = new \Phalcon\Cache($adapter);

    return $cache;
});

Soo... maybe the mistake is Phalcon\Cache, but this works in Phalcon 4.x. So how must be changed?

Thanks :)
And may the force be with you!

Details

  • Phalcon version: v5.0.0-alpha.2
  • PHP Version: 8.0.6
  • Operating System: Windows
  • Server: Apache
@borisdelev borisdelev added bug A bug report status: unverified Unverified labels May 6, 2021
@Jeckerson Jeckerson added 5.0 The issues we want to solve in the 5.0 release status: high High and removed status: unverified Unverified labels May 6, 2021
@BeMySlaveDarlin
Copy link
Contributor

Can you provide code part around this line?
v1\modules\client\controllers\ControllerBase.php on line 33
I suppose you providing wrong object.

As is see in error, you trying to:

$simpleResultset = new Simple($columnMap, $model, $resultset, $this->modelsCache);

Can you try next change?

$simpleResultset = new Simple($columnMap, $model, $resultset, $this->modelsCache->getAdapter());

@borisdelev
Copy link
Contributor Author

Line 33 is that line with "key=" from ::find, but i will be more specific later, just to back home.

@borisdelev
Copy link
Contributor Author

image
image

I think now its better. I did not have "$simpleResultset" but if u want me to try something... i am here! I will try to debug some more.

@borisdelev
Copy link
Contributor Author

image

@BeMySlaveDarlin
Copy link
Contributor

Can you try this one?

$di->set('modelsCache', function () use ($config) {
    $serializerFactory = new \Phalcon\Storage\SerializerFactory();

    return new \Phalcon\Cache\Adapter\Stream($serializerFactory, [
        'storageDir' => BASE_PATH . 'cache/queries/',
        'lifetime' => $config->development ? 60 : 60 * 60 * 24 * 7,
    ]);
});

@borisdelev
Copy link
Contributor Author

I confirm that this work in Phalcon 4x and Phalcon 5.0.0 alpha-2.
If that is the way to set cache service- documentation must be fixed here: https://docs.phalcon.io/4.0/en/db-models-cache#resultsets (i can do that...). I am pretty sure there is more places with that service examples and i will find them.

I will test other type of cache to see if all works fine.

Well... thanks! A lot :) U awesome!

@Jeckerson Jeckerson added documentation Documentation required enhancement Enhancement to the framework and removed bug A bug report status: high High labels May 9, 2021
@BeMySlaveDarlin
Copy link
Contributor

BeMySlaveDarlin commented May 9, 2021

If that is the way to set cache service- documentation must be fixed here...

Its only related to modelsCache service due to the way Query using it.

@borisdelev
Copy link
Contributor Author

@BeMySlaveDarlin so its not related with other cache stuff? Ok, cool. Thanks
Anyway, is here must be fixed too: https://docs.phalcon.io/4.0/en/cache#cache-1 ?

@BeMySlaveDarlin
Copy link
Contributor

Nope, only modelsCache service. The rest of services works fine.

@borisdelev
Copy link
Contributor Author

Lov u guys xD
... Cant wait Phalcon 6... then i can contribute and help more.

Best wishes.

@niden
Copy link
Member

niden commented May 10, 2021

I actually managed to reproduce this. It only happens in PHP 8 and the solution is to use CacheInterface vs AdapterInterface

I should have something ready very soon.

@niden niden reopened this May 10, 2021
@niden niden mentioned this issue May 10, 2021
5 tasks
@niden niden linked a pull request May 10, 2021 that will close this issue
5 tasks
@niden niden added breaks bc Functionality that breaks Backwards Compatibility and removed enhancement Enhancement to the framework labels May 10, 2021
@niden niden added bug A bug report status: medium Medium labels May 10, 2021
@Jeckerson
Copy link
Member

Fixed in #15478

@niden niden moved this to Released in Phalcon v5 Aug 25, 2022
@niden niden added this to Phalcon v5 Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release breaks bc Functionality that breaks Backwards Compatibility bug A bug report documentation Documentation required status: medium Medium
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants