1313
1414use Psr \Cache \CacheItemPoolInterface ;
1515use Symfony \AI \Agent \Chat \MessageStoreInterface ;
16- use Symfony \AI \Agent \Chat \SessionAwareMessageStoreInterface ;
1716use Symfony \AI \Agent \Exception \RuntimeException ;
1817use Symfony \AI \Platform \Message \MessageBag ;
1918use Symfony \AI \Platform \Message \MessageBagInterface ;
2019use Symfony \Component \Uid \AbstractUid ;
2120use Symfony \Component \Uid \TimeBasedUidInterface ;
2221
23- final readonly class CacheStore implements MessageStoreInterface, SessionAwareMessageStoreInterface
22+ final readonly class CacheStore implements MessageStoreInterface
2423{
2524 public function __construct (
2625 private CacheItemPoolInterface $ cache ,
27- private string $ cacheKey ,
2826 private int $ ttl = 86400 ,
2927 ) {
3028 if (!interface_exists (CacheItemPoolInterface::class)) {
@@ -34,28 +32,23 @@ public function __construct(
3432
3533 public function save (MessageBagInterface $ messages ): void
3634 {
37- $ item = $ this ->cache ->getItem ($ this -> cacheKey );
35+ $ item = $ this ->cache ->getItem ($ messages -> getSession ()-> toRfc4122 () );
3836
3937 $ item ->set ($ messages );
4038 $ item ->expiresAfter ($ this ->ttl );
4139
4240 $ this ->cache ->save ($ item );
4341 }
4442
45- public function load (): MessageBag
43+ public function load (AbstractUid & TimeBasedUidInterface $ session ): MessageBagInterface
4644 {
47- $ item = $ this ->cache ->getItem ($ this -> cacheKey );
45+ $ item = $ this ->cache ->getItem ($ session -> toRfc4122 () );
4846
4947 return $ item ->isHit () ? $ item ->get () : new MessageBag ();
5048 }
5149
52- public function clear (): void
50+ public function clear (AbstractUid & TimeBasedUidInterface $ session ): void
5351 {
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 ());
6053 }
6154}
0 commit comments