# I am new to Laminas, I need to know how Cache works

**URL:** <https://discourse.laminas.dev/t/i-am-new-to-laminas-i-need-to-know-how-cache-works/2925>\
**Category:** Components & MVC\
**Tags:** laminas-mvc, laminas-cache\
**Created:** [June 16, 2022, 1:36pm UTC](https://discourse.laminas.dev/t/i-am-new-to-laminas-i-need-to-know-how-cache-works/2925 "2022-06-16T13:36:38Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [June 20, 2022, 12:05pm UTC](https://discourse.laminas.dev/t/i-am-new-to-laminas-i-need-to-know-how-cache-works/2925/2 "2022-06-20T12:05:43Z")

</div>

Hello and welcome to our forums! 😃

> [@irfan](#):
>
> If anybody provides a complete working example…

Before starting, make sure a cache adapter is installed, like the APCu or the Filesystem adapter.

Here is an example which uses two different cache adapters as storage for the cache:

```php
require_once __DIR__. '/vendor/autoload.php';

$config = (new Laminas\ConfigAggregator\ConfigAggregator([
    Laminas\Cache\ConfigProvider::class,
    Laminas\Cache\Storage\Adapter\BlackHole\ConfigProvider::class,
    Laminas\Cache\Storage\Adapter\Memory\ConfigProvider::class,
]))->getMergedConfig();

$container = new Laminas\ServiceManager\ServiceManager($config['dependencies']);

/** @var Laminas\Cache\Service\StorageAdapterFactoryInterface $storageFactory */
$storageFactory = $container->get(
    Laminas\Cache\Service\StorageAdapterFactoryInterface::class
);

$storage1 = $storageFactory->create(Laminas\Cache\Storage\Adapter\BlackHole::class);
$storage2 = $storageFactory->create(Laminas\Cache\Storage\Adapter\Memory::class);

$storage1->setItem('key', 'value');
if ($storage1->hasItem('key')) {
    echo $storage1->getItem('key'); // "value"
}

$storage2->setItem('key', 'value');
if ($storage2->hasItem('key')) {
    echo $storage2->getItem('key'); // "value"
}

```

Check also the quick start and the example section:

- [Adapters - laminas-cache - Laminas Docs](https://docs.laminas.dev/laminas-cache/v3/storage/adapter/#quick-start)
- [Adapters - laminas-cache - Laminas Docs](https://docs.laminas.dev/laminas-cache/v3/storage/adapter/#examples)

---

_[View the full topic](https://discourse.laminas.dev/t/i-am-new-to-laminas-i-need-to-know-how-cache-works/2925)._
