mauretto78 / in-memory-list-bundle
PHP Bundle
Installs: 36
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Type:symfony-bundle
Requires
- mauretto78/in-memory-list: ^2.0
- sensio/framework-extra-bundle: ^3.0|^4.0
- symfony/config: ^2.3|^3.0|^4.0
- symfony/dependency-injection: ^2.3|^3.0|^4.0
- symfony/framework-bundle: ^3.3|^4.0|^5.0
- symfony/http-kernel: ^2.3|^3.0|^4.0
- symfony/yaml: ^2.3|^3.0|^4.0
- twig/extensions: ^1.5
README
This is the official Symfony bundle for In-Memory List package.
Install Guide
Step 1: Include In-Memory List Bundle in your project with composer:
composer require mauretto78/in-memory-list-bundle
Step 2: Setup your config.yml to configure your driver and connection parameters
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.
Step 3: Setup your AppKernel.php by adding the InMemoryList Bundle
// .. $bundles[] = new InMemoryList\Bundle\InMemoryListBundle();
Step 4: Setup yor routing_dev.yml
Add these lines at the bottom of your routing_dev.yml
file:
_inmemorylist: resource: '@InMemoryListBundle/Resources/config/routing.yml'
Usage Guide
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 %}
Symfony Profiler
You can manage cached lists through the Symfony Profiler:
Support
If you found an issue or had an idea please refer to this section.
Authors
- Mauro Cassani - github
License
This project is licensed under the MIT License - see the LICENSE.md file for details