13
13
14
14
use Psr \Cache \CacheItemPoolInterface ;
15
15
use Symfony \AI \Agent \Chat \MessageStoreInterface ;
16
- use Symfony \AI \Agent \Chat \SessionAwareMessageStoreInterface ;
17
16
use Symfony \AI \Agent \Exception \RuntimeException ;
18
17
use Symfony \AI \Platform \Message \MessageBag ;
19
18
use Symfony \AI \Platform \Message \MessageBagInterface ;
20
19
use Symfony \Component \Uid \AbstractUid ;
21
20
use Symfony \Component \Uid \TimeBasedUidInterface ;
22
21
23
- final readonly class CacheStore implements MessageStoreInterface, SessionAwareMessageStoreInterface
22
+ final readonly class CacheStore implements MessageStoreInterface
24
23
{
25
24
public function __construct (
26
25
private CacheItemPoolInterface $ cache ,
27
- private string $ cacheKey ,
28
26
private int $ ttl = 86400 ,
29
27
) {
30
28
if (!interface_exists (CacheItemPoolInterface::class)) {
@@ -34,28 +32,23 @@ public function __construct(
34
32
35
33
public function save (MessageBagInterface $ messages ): void
36
34
{
37
- $ item = $ this ->cache ->getItem ($ this -> cacheKey );
35
+ $ item = $ this ->cache ->getItem ($ messages -> getSession ()-> toRfc4122 () );
38
36
39
37
$ item ->set ($ messages );
40
38
$ item ->expiresAfter ($ this ->ttl );
41
39
42
40
$ this ->cache ->save ($ item );
43
41
}
44
42
45
- public function load (): MessageBag
43
+ public function load (AbstractUid & TimeBasedUidInterface $ session ): MessageBagInterface
46
44
{
47
- $ item = $ this ->cache ->getItem ($ this -> cacheKey );
45
+ $ item = $ this ->cache ->getItem ($ session -> toRfc4122 () );
48
46
49
47
return $ item ->isHit () ? $ item ->get () : new MessageBag ();
50
48
}
51
49
52
- public function clear (): void
50
+ public function clear (AbstractUid & TimeBasedUidInterface $ session ): void
53
51
{
54
- $ this ->cache ->deleteItem ($ this ->cacheKey );
55
- }
56
-
57
- public function withSession (AbstractUid &TimeBasedUidInterface $ session ): MessageStoreInterface &SessionAwareMessageStoreInterface
58
- {
59
- return new self ($ this ->cache , $ session ->toRfc4122 (), $ this ->ttl );
52
+ $ this ->cache ->deleteItem ($ session ->toRfc4122 ());
60
53
}
61
54
}
0 commit comments