Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Is there a tutorial or example on how to use the cache class?
  • I sort of get the idea based on the documentation, but it would really help to see a real example of how to use the cache class.
  • HarroHarro
    Accepted Answer
    It's very simple:

    try
    {
        // retrieve a value from cache
        $cached_value = \Cache::get('somevalue');
    }
    catch (\CacheNotFoundException $e)
    {
        // not found in cache, construct the value
        $cached_value = 'some_value';

        // and store it in cache for up to an hour
       \Cache::set('somevalue, $cached_value, 3600);
    }
  • Let's say you retrieve the value in the cache using \Cache::get().... Does this function reset the expiration of the cache?
    Also, is the expiration based on the files "modified" time, "created_at" or some internal value managed by fuelphp? Basically, I want to know what parameters to look for when performing a cron job. -thanks!
  • No, it doesn't. If you want to renew it after a get(), you need to set() it again.

    The expiration is stored as part of the metadata of the cache object, as it has to function independently of the storage mechanism used.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion