Sitansu
Sitansu

Reputation: 891

Set cache time in symfony

I am using file cache in symfony to store my data for some time limit.Below is the code i have written.

$c = new sfFileCache(array('cache_dir' => sfConfig::get('sf_cache_dir').'/function'));
        if ($c->has('myarray')) {
            $cached = $c->get('myarray');
            if (!empty($cached)) {
                $data = unserialize($cached);
            }
        } else {
            foreach($queries as $key => $query) {
                foreach ($query->fetchArray() As $result) {
                    $data[] = $result;
                }
            }
            $c->set('myarray',serialize($data));
        }

Can anybody tell how to set time limit for file cache in symfony so that the cache will be automatically destroyed after an hour.

Upvotes: 0

Views: 1151

Answers (2)

Pedro Casado
Pedro Casado

Reputation: 1745

just sharing my code for the ones using APC. should be quite the same. i just passed the prefix "query" since i was caching a query.

$cache = new sfAPCCache(array('lifetime' => 600, 'prefix' => 'query'));

Upvotes: 0

j0k
j0k

Reputation: 22756

Simply:

$c = new sfFileCache(array(
  'cache_dir' => sfConfig::get('sf_cache_dir').'/function',
  'lifetime'  => 3600
));

See the code to learn about other option from sfCache.

Upvotes: 1

Related Questions