This is the official Symfony bundle for In-Memory List package.
composer require mauretto78/in-memory-list-bundle
Here is an example:
# In Memory List
in_memory_list:
driver: 'redis'
parameters:
scheme: 'tcp'
host: '127.0.0.1'
port: '6379'
options:
profile: '3.2'
Please refer to In-Memory List page for more details.
// ..
$bundles[] = new InMemoryList\Bundle\InMemoryListBundle();
Add these lines at the bottom of your routing_dev.yml
file:
_inmemorylist:
resource: '@InMemoryListBundle/Resources/config/routing.yml'
Caching data in your controller:
public function indexAction(Request $request)
{
$simpleArray = json_encode([
[
'userId' => 1,
'id' => 1,
'title' => 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
'body' => "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto",
],
[
'userId' => 1,
'id' => 2,
'title' => 'qui est esse',
'body' => "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla",
],
]);
/** @var Cache $cache */
$cache = $this->container->get('in_memory_list');
$cachedList = $cache->getClient()->create(json_decode($simpleArray), ['uuid' => 'simple-list', 'ttl' => 1000]);
// replace this example code with whatever you need
return $this->render('default/index.html.twig', [
'cachedList' => $cachedList,
'base_dir' => realpath($this->getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR,
]);
}
Now you can loop data in your twig files:
{% for item in cachedList %}
<li>{{ item.userId }}</li>
<li>{{ item.id }}</li>
<li>{{ item.title }}</li>
<li>{{ item.body }}</li>
{% endfor %}
You can manage cached lists through the Symfony Profiler:
If you found an issue or had an idea please refer to this section.
- Mauro Cassani - github
This project is licensed under the MIT License - see the LICENSE.md file for details