1616use Symfony \Component \Cache \CacheInterface ;
1717use Symfony \Component \Cache \CacheItem ;
1818use Symfony \Component \Cache \Exception \InvalidArgumentException ;
19+ use Symfony \Component \Cache \Marshaller \DefaultMarshaller ;
1920use Symfony \Component \Cache \PruneableInterface ;
2021use Symfony \Component \Cache \ResettableInterface ;
2122use Symfony \Component \Cache \Traits \GetTrait ;
@@ -34,6 +35,7 @@ class PhpArrayAdapter implements AdapterInterface, CacheInterface, PruneableInte
3435 use GetTrait;
3536
3637 private $ createCacheItem ;
38+ private $ marshaller ;
3739
3840 /**
3941 * @param string $file The PHP file were values are cached
@@ -88,6 +90,7 @@ public function get(string $key, callable $callback, float $beta = null)
8890 $ this ->initialize ();
8991 }
9092 if (!isset ($ this ->keys [$ key ])) {
93+ get_from_pool:
9194 if ($ this ->pool instanceof CacheInterface) {
9295 return $ this ->pool ->get ($ key , $ callback , $ beta );
9396 }
@@ -99,11 +102,16 @@ public function get(string $key, callable $callback, float $beta = null)
99102 if ('N; ' === $ value ) {
100103 return null ;
101104 }
102- if ($ value instanceof \Closure) {
103- return $ value ();
104- }
105- if (\is_string ($ value ) && isset ($ value [2 ]) && ': ' === $ value [1 ]) {
106- return unserialize ($ value );
105+ try {
106+ if ($ value instanceof \Closure) {
107+ return $ value ();
108+ }
109+ if (\is_string ($ value ) && isset ($ value [2 ]) && ': ' === $ value [1 ]) {
110+ return ($ this ->marshaller ?? $ this ->marshaller = new DefaultMarshaller ())->unmarshall ($ value );
111+ }
112+ } catch (\Throwable $ e ) {
113+ unset($ this ->keys [$ key ]);
114+ goto get_from_pool;
107115 }
108116
109117 return $ value ;
@@ -278,7 +286,7 @@ private function generateItems(array $keys): \Generator
278286 }
279287 } elseif (\is_string ($ value ) && isset ($ value [2 ]) && ': ' === $ value [1 ]) {
280288 try {
281- yield $ key => $ f ($ key , unserialize ($ value ), true );
289+ yield $ key => $ f ($ key , $ this -> unserializeValue ($ value ), true );
282290 } catch (\Throwable $ e ) {
283291 yield $ key => $ f ($ key , null , false );
284292 }
0 commit comments