mauretto78 / in-memory-list-bundle
PHP 扩展包
v1.0.11
2019-05-21 12:19 UTC
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
这是 In-Memory List 包的官方 Symfony 扩展包。
安装指南
步骤 1: 使用 composer 将 In-Memory List 扩展包包含到你的项目中
composer require mauretto78/in-memory-list-bundle
步骤 2: 配置你的 config.yml 文件以设置驱动程序和连接参数
以下是一个示例
# In Memory List in_memory_list: driver: 'redis' parameters: scheme: 'tcp' host: '127.0.0.1' port: '6379' options: profile: '3.2'
有关更多详细信息,请参阅 In-Memory List 页面。
步骤 3: 通过添加 InMemoryList 扩展包来配置你的 AppKernel.php
// .. $bundles[] = new InMemoryList\Bundle\InMemoryListBundle();
步骤 4: 配置你的 routing_dev.yml
在你的 routing_dev.yml
文件底部添加以下行
_inmemorylist: resource: '@InMemoryListBundle/Resources/config/routing.yml'
使用指南
在控制器中缓存数据
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, ]); }
现在你可以在 twig 文件中循环数据
{% for item in cachedList %} <li>{{ item.userId }}</li> <li>{{ item.id }}</li> <li>{{ item.title }}</li> <li>{{ item.body }}</li> {% endfor %}
Symfony 分析器
你可以通过 Symfony 分析器来管理缓存的列表
支持
如果你发现了一个问题或有一个想法,请参考 这一部分。
作者
- Mauro Cassani - github
许可证
本项目遵循 MIT 许可证 - 有关详细信息,请参阅 LICENSE.md 文件