mauretto78/in-memory-list-bundle

PHP Bundle

v1.0.11 2019-05-21 12:19 UTC

This package is not auto-updated.

Last update: 2024-05-11 18:18:22 UTC


README

SensioLabsInsight Codacy Badge license Packagist

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:

Symfony Profiler

Support

If you found an issue or had an idea please refer to this section.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details