/
CacheableModule.php
64 lines (58 loc) · 2.08 KB
/
CacheableModule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace BEAR\QueryRepository;
use BEAR\RepositoryModule\Annotation\AbstractCacheControl;
use BEAR\RepositoryModule\Annotation\Cacheable;
use BEAR\RepositoryModule\Annotation\Commands;
use BEAR\RepositoryModule\Annotation\Purge;
use BEAR\RepositoryModule\Annotation\Refresh;
use BEAR\Sunday\Extension\Transfer\HttpCacheInterface;
use Ray\Di\AbstractModule;
final class CacheableModule extends AbstractModule
{
/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this->bind(HttpCacheInterface::class)->to(HttpCache::class);
$this->bind()->annotatedWith(Commands::class)->toProvider(CommandsProvider::class);
$this->bind(RefreshInterceptor::class);
$this->install(new StorageExpiryModule(60, 60 * 60, 60 * 60 * 24));
$this->installAopModule();
}
protected function installAopModule(): void
{
$this->bindPriorityInterceptor(
$this->matcher->annotatedWith(Cacheable::class),
$this->matcher->startsWith('onGet'),
[CacheInterceptor::class]
);
$this->bindInterceptor(
$this->matcher->annotatedWith(Cacheable::class),
$this->matcher->logicalOr(
$this->matcher->startsWith('onPut'),
$this->matcher->logicalOr(
$this->matcher->startsWith('onPatch'),
$this->matcher->startsWith('onDelete')
)
),
[CommandInterceptor::class]
);
$this->bindInterceptor(
$this->matcher->logicalNot(
$this->matcher->annotatedWith(Cacheable::class)
),
$this->matcher->logicalOr(
$this->matcher->annotatedWith(Purge::class),
$this->matcher->annotatedWith(Refresh::class)
),
[RefreshInterceptor::class]
);
$this->bindInterceptor(
$this->matcher->annotatedWith(AbstractCacheControl::class),
$this->matcher->startsWith('onGet'),
[HttpCacheInterceptor::class]
);
}
}