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

Cache is not invalidated properly when adding a decorated method to a cached aspect #81

Closed
HighLiuk opened this issue Jun 17, 2024 · 0 comments · Fixed by #82
Closed

Comments

@HighLiuk
Copy link
Contributor

HighLiuk commented Jun 17, 2024

If you add a (decorated) method on an aspect which is already cached, the cache is not invalidated and the method is not run.

Steps to reproduce:

src/Bar.php

namespace App;

class Bar
{
    public function bar(): void
    {
        echo "bar\n";
    }
}

src/Aop/MyAspect.php

namespace App\Aop;

use App\Bar;
use Okapi\Aop\Attributes\After;
use Okapi\Aop\Attributes\Around;
use Okapi\Aop\Attributes\Aspect;

#[Aspect]
class MyAspect
{
    #[Around(Bar::class, 'bar')]
    public function foo(): void
    {
        echo "foo\n";
    }

    // #[After(Bar::class, 'bar')]
    // public function baz(): void
    // {
    //     echo "baz\n";
    // }
}

src/Aop/Kernel.php

namespace App\Aop;

use Okapi\Aop\AopKernel;

class Kernel extends AopKernel
{
    protected array $aspects = [
        MyAspect::class,
    ];   
}

main.php

use App\Aop\Kernel;

require_once __DIR__ . '/vendor/autoload.php';

Kernel::init();

$bar = new App\Bar();
$bar->bar();

If you run rm -rf cache && php main.php this is the output as expected: foo bar. If you then uncomment the baz method and run php main.php again, the output is still foo bar, but if you run rm -rf cache && php main.php again, you'll get the correct foo bar baz output.

May this be related with #61? If that's the case, the contents hash or filemtime should be used as key for invalidating, probably.

@HighLiuk HighLiuk mentioned this issue Jun 18, 2024
WalterWoshid added a commit that referenced this issue Jun 18, 2024
WalterWoshid pushed a commit that referenced this issue Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant