PhpArrayCacheWrapper.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Cache\Tests\Simple;
  11. use Symfony\Component\Cache\Simple\PhpArrayCache;
  12. class PhpArrayCacheWrapper extends PhpArrayCache
  13. {
  14. protected $data = [];
  15. public function set($key, $value, $ttl = null)
  16. {
  17. (\Closure::bind(function () use ($key, $value) {
  18. $this->data[$key] = $value;
  19. $this->warmUp($this->data);
  20. list($this->keys, $this->values) = eval(substr(file_get_contents($this->file), 6));
  21. }, $this, PhpArrayCache::class))();
  22. return true;
  23. }
  24. public function setMultiple($values, $ttl = null)
  25. {
  26. if (!\is_array($values) && !$values instanceof \Traversable) {
  27. return parent::setMultiple($values, $ttl);
  28. }
  29. (\Closure::bind(function () use ($values) {
  30. foreach ($values as $key => $value) {
  31. $this->data[$key] = $value;
  32. }
  33. $this->warmUp($this->data);
  34. list($this->keys, $this->values) = eval(substr(file_get_contents($this->file), 6));
  35. }, $this, PhpArrayCache::class))();
  36. return true;
  37. }
  38. }