# How to cache query result in slim?

**URL:** <https://discourse.slimframework.com/t/how-to-cache-query-result-in-slim/2148>\
**Category:** Questions\
**Created:** [January 8, 2018, 1:21pm UTC](https://discourse.slimframework.com/t/how-to-cache-query-result-in-slim/2148 "2018-01-08T13:21:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahesh](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@mahesh](https://discourse.slimframework.com/u/mahesh)\
**Post date:** [January 8, 2018, 1:21pm UTC](https://discourse.slimframework.com/t/how-to-cache-query-result-in-slim/2148/1 "2018-01-08T13:21:54Z")

</div>

Hi

I want to cache frequently used queries and send them back without calling database.  
I am using eloquent with slim framework.

Please guide me how to do it

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [January 8, 2018, 8:29pm UTC](https://discourse.slimframework.com/t/how-to-cache-query-result-in-slim/2148/2 "2018-01-08T20:29:44Z")

</div>

Hi!

~~I haven’t tested it myself yet, but maybe that could be a solution:~~

~~[Rememberable, Laravel 5 query cache](https://github.com/dwightwatson/rememberable)~~

Edit / Note: Rememberable interfaces directly with Laravel and depends on the app() function provided by it. The developer has no plans to support use outside of Laravel.

---

<div class="post-metadata">

**Author:** ![mahesh](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@mahesh](https://discourse.slimframework.com/u/mahesh)\
**Post date:** [January 9, 2018, 4:43am UTC](https://discourse.slimframework.com/t/how-to-cache-query-result-in-slim/2148/3 "2018-01-09T04:43:05Z")

</div>

Can i implement memcached in slimframework? Please give me some guide for this.

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [January 9, 2018, 2:54pm UTC](https://discourse.slimframework.com/t/how-to-cache-query-result-in-slim/2148/4 "2018-01-09T14:54:15Z")

</div>

> Can i implement memcached in slimframework?

Yes. You just need the memcached PHP extension:  
[http://php.net/manual/en/book.memcached.php](http://php.net/manual/en/book.memcached.php)  
[http://php.net/manual/en/memcached.installation.php](http://php.net/manual/en/memcached.installation.php)

Just add a new entry to your container:

```php
$container['memcached'] = function (Container $container) {
    $mc = new Memcached(); 
    $mc->addServer("127.0.0.1", 11211);
    return $mc;
}

```

Usage

```php
$mc = $container->get('memcached');
$mc->set("foo", "Hello!"); 
$mc->set("bar", "Memcached...");

```

---

<div class="post-metadata">

**Author:** ![ekumahost](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/ekumahost/32/639_2.png) [@ekumahost](https://discourse.slimframework.com/u/ekumahost)\
**Post date:** [March 8, 2018, 4:47pm UTC](https://discourse.slimframework.com/t/how-to-cache-query-result-in-slim/2148/5 "2018-03-08T16:47:47Z")

</div>

@mahesh have you found a solution,.?
