Skip to content

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

@HighLiuk

Description

@HighLiuk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions