@@ -31,6 +31,7 @@ class ProxyAdapter implements AdapterInterface, CacheInterface, PruneableInterfa
3131private $ namespace ;
3232private $ namespaceLen ;
3333private $ createCacheItem ;
34+ private $ setInnerItem ;
3435private $ poolHash ;
3536
3637public function __construct (CacheItemPoolInterface $ pool ,string $ namespace ='' ,int $ defaultLifetime =0 )
@@ -43,32 +44,52 @@ public function __construct(CacheItemPoolInterface $pool, string $namespace = ''
4344function ($ key ,$ innerItem )use ($ defaultLifetime ,$ poolHash ) {
4445$ item =new CacheItem ();
4546$ item ->key =$ key ;
46- $ item ->value =$ innerItem ->get ();
47+ $ item ->value =$ v = $ innerItem ->get ();
4748$ item ->isHit =$ innerItem ->isHit ();
4849$ item ->defaultLifetime =$ defaultLifetime ;
4950$ item ->innerItem =$ innerItem ;
5051$ item ->poolHash =$ poolHash ;
52+ if (\is_array ($ v ) &&1 ===\count ($ v ) &&\is_array ($ v =$ v [CacheItem::STATS_KEY ] ??null ) &&array (0 ,1 ) ===\array_keys ($ v )) {
53+ list ($ item ->value ,$ item ->stats ) =$ v ;
54+ }elseif ($ innerIteminstanceof CacheItem) {
55+ $ item ->stats =$ innerItem ->stats ;
56+ }
5157$ innerItem ->set (null );
5258
5359return $ item ;
5460 },
5561null ,
5662 CacheItem::class
5763 );
64+ $ this ->setInnerItem = \Closure::bind (
65+ function (CacheItemInterface $ innerItem ,array $ item ) {
66+ if ($ stats =$ item ["\0* \0newStats " ]) {
67+ $ item ["\0* \0value " ] =array (CacheItem::STATS_KEY =>array ($ item ["\0* \0value " ],$ stats ));
68+ }
69+ $ innerItem ->set ($ item ["\0* \0value " ]);
70+ $ innerItem ->expiresAt (null !==$ item ["\0* \0expiry " ] ? \DateTime::createFromFormat ('U ' ,$ item ["\0* \0expiry " ]) :null );
71+ },
72+ null ,
73+ CacheItem::class
74+ );
5875 }
5976
6077/**
6178 * {@inheritdoc}
6279 */
63- public function get (string $ key ,callable $ callback )
80+ public function get (string $ key ,callable $ callback, float $ beta = null )
6481 {
6582if (!$ this ->pool instanceof CacheInterface) {
66- return $ this ->doGet ($ this -> pool ,$ key ,$ callback );
83+ return $ this ->doGet ($ this ,$ key ,$ callback, $ beta ?? 1.0 );
6784 }
6885
6986return $ this ->pool ->get ($ this ->getId ($ key ),function ($ innerItem )use ($ key ,$ callback ) {
70- return $ callback (($ this ->createCacheItem )($ key ,$ innerItem ));
71- });
87+ $ item = ($ this ->createCacheItem )($ key ,$ innerItem );
88+ $ item ->set ($ value =$ callback ($ item ));
89+ ($ this ->setInnerItem )($ innerItem , (array )$ item );
90+
91+ return $ value ;
92+ },$ beta );
7293 }
7394
7495/**
@@ -164,13 +185,11 @@ private function doSave(CacheItemInterface $item, $method)
164185return false ;
165186 }
166187$ item = (array )$ item ;
167- $ expiry =$ item ["\0* \0expiry " ];
168- if (null ===$ expiry &&0 <$ item ["\0* \0defaultLifetime " ]) {
169- $ expiry =time () +$ item ["\0* \0defaultLifetime " ];
188+ if (null ===$ item ["\0* \0expiry " ] &&0 <$ item ["\0* \0defaultLifetime " ]) {
189+ $ item ["\0* \0expiry " ] =time () +$ item ["\0* \0defaultLifetime " ];
170190 }
171191$ innerItem =$ item ["\0* \0poolHash " ] ===$ this ->poolHash ?$ item ["\0* \0innerItem " ] :$ this ->pool ->getItem ($ this ->namespace .$ item ["\0* \0key " ]);
172- $ innerItem ->set ($ item ["\0* \0value " ]);
173- $ innerItem ->expiresAt (null !==$ expiry ? \DateTime::createFromFormat ('U ' ,$ expiry ) :null );
192+ ($ this ->setInnerItem )($ innerItem ,$ item );
174193
175194return $ this ->pool ->$ method ($ innerItem );
176195 }