【发布时间】:2020-07-26 18:35:08
【问题描述】:
我有一个要从数据库显示的数组,经过许多业务实施后,我需要 1~2 分钟的时间来获得最终输出。因此,在使用 UI 进行测试时,这个过程让我很烦。所以我决定将这个最终数组存储到缓存中。我尝试使用以下代码行将myArray 存储到缓存中。
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Contracts\Cache\ItemInterface;
$cache = new FilesystemAdapter();
// The callable will only be executed on a cache miss.
$output = $cache->get('my_cache_key', function (ItemInterface $item) use ($myArray) {
$item->expiresAfter(7200);
return $this->serializer->provideSerializer()->serialize($myArray, 'json');
});
我认为从缓存读取时应该更快,但加载数据仍然需要相同的时间。
谁能帮助我如何将我的数组存储到缓存中,以便下次加载更快。
谢谢。
【问题讨论】: