Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Get cache expiration time
  • Hello again,

    I was wondering if it was possible to get some more details about a stored Cache, generated using the Cache libraries.

    When calling Cache::get("some_cache") the unserialized contents of the cache is returned which is great, but I'm not sure how exactly you're supposed to find out more information about the cache store itself.

    For example, how do I found out how long left a cache has before it's considered expired? How do I find out when it was created? Size of the cache? And so on. Do I have to read the file manually to find this out or are there methods to do this for you already?

    I'm currently using the file-based cache driver but I was thinking that this question would apply to all cache drivers.

    Cheers,
  • HarroHarro
    Accepted Answer
    If you want to go beyond the simple static interface, you'll need to switch to "advanced usage".

    Use Cache::forge("some_cache") instead.

    It will return a Cache_Storage_Driver instance with your cache data in it. It has a getter for object properties like expiration...
  • Would you mind providing an example?

    The code

    Cache::get("some_cache");

    Correctly returns the unserialized data, but:

    $cache = Cache::forge('some_cache');
    Debug::dump($cache);

    shows a Fuel\Core\Cache_Storage_File with a good portion of the objects fields as null including the expiration and contents fields.

    Unfortunately the documentation on advanced Cache usage is a little bear so I'm kind of lost on exactly how we're supposed to do this.

    EDIT:

    Okay, turns out
    $cache = Cache::forge("some_cache");
    $cache->get();
    Debug::dump($cache);

    Successfully populates the cache object field, but all of the properties are protected so I can't just access them using:

    $cache->expiration

    I've looked through the source code and see no obvious getter for the cache fields. Am I just being blind?

    EDIT 2

    Finally figured out how to do this. The full working code (for me) is:

    $cache = Fuel\Core\Cache::forge('some_cache');
    $cache->get();
    Debug::dump($cache->get_expiration());

    Some documentation on this really wouldn't go a miss :)
  • It's on our very long todo list.

    You're the first one in two years that has asked about it... ;-)

Howdy, Stranger!

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

In this Discussion