# Cache Duration Not Working

**URL:** <https://discourse.cakephp.org/t/cache-duration-not-working/3077>\
**Category:** Need Help\
**Created:** [August 23, 2017, 11:12am UTC](https://discourse.cakephp.org/t/cache-duration-not-working/3077 "2017-08-23T11:12:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev.drawtopic](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@dev.drawtopic](https://discourse.cakephp.org/u/dev.drawtopic)\
**Post date:** [August 23, 2017, 11:12am UTC](https://discourse.cakephp.org/t/cache-duration-not-working/3077/1 "2017-08-23T11:12:06Z")

</div>

I have been implementing cache . Works fine!, but durations seems to be not working. The time I have files are not lasting till that time . May be i could be wrong, I am creating user-wise caches, Please let me know best practices.  
My Code follows :  
//config/app.php  
’Cache’ =\> [  
‘default’ =\> [  
‘className’ =\> ‘File’,  
‘path’ =\> CACHE,  
‘url’ =\> env(‘CACHE\_DEFAULT\_URL’, null),  
],  
‘short’ =\> [  
‘className’ =\> ‘File’,  
‘duration’ =\> ‘+60 minutes’,  
‘path’ =\> CACHE,  
‘prefix’ =\> ‘cake\_short\_’  
],

```
    /**
     * Configure the cache used for general framework caching.
     * Translation cache files are stored with this configuration.
     * Duration will be set to '+1 year' in bootstrap.php when debug = false
     * If you set 'className' => 'Null' core cache will be disabled.
     */
    '_cake_core_' => [
        'className' => 'File',
        'prefix' => 'myapp_cake_core_',
        'path' => CACHE . 'persistent/',
        'serialize' => true,
        'duration' => '+2 minutes',
        'url' => env('CACHE_CAKECORE_URL', null),
    ],

```

I have created a component called short copied from the Docs :  
Below is the code that i used to create cache :  
Cache::write(“data\_$user[0]”, $data,‘short’);  
This works fine file is created corresponding to the logged in user. But after few minutes it is deleted (May be 2 minutes).  
Is there any mistake i am making ?

---

<div class="post-metadata">

**Author:** ![dev.drawtopic](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@dev.drawtopic](https://discourse.cakephp.org/u/dev.drawtopic)\
**Post date:** [August 24, 2017, 5:27am UTC](https://discourse.cakephp.org/t/cache-duration-not-working/3077/2 "2017-08-24T05:27:10Z")

</div>

Ok fine, I got the issue by myself.  
Cache::clear(false);  
was written somewhere in my code. when ever that function was called cache were clearing and cache files were getting deleting. When i commented out this line caches were being maintained.  
Thanks for not helping 😃
