Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
request class and cache
  • One of the things I like about the Kohana request class is that I can pass an HTTP_Cache object and it will use it to cache the response of the request. this is a very useful feature, and I was wondering if FuelPHP supports something similar, I didn't see anything in the docs, but I thought I should ask in case this is something that hasn't been documented yet. Thank you.
  • The Request class doesn't have any built-in caching capabilities. But you only need a few lines of code to cache the result using the Cache class, for example with a hash of the URI as cache key.
    $key = sha1(Uri::current());
    try
    {
        $response = Cache::get($key);
    }
    catch (\CacheNotFoundException $e)
    {
        $response = Request::forge()->execute()->response();
        Cache::set($key, $response, 300);
    }
    

    If you add this to your index.php all your pages will be cached for 5 minutes.
  • Uri::current() in public/assets/index.php doesn't work, do you now why ?
  • Uri::current() is a method in a Framework class, it requires the framework to be operational.

    I don't know what is in that index.php, so I can't tell you why it doesn't work.
  • Wonderful snip of code: I think it can be very useful, I think I'll put in in my packages.

    What about an application functionality about it? Like a config file with a whitelist / blacklist of api that we can cache.

Howdy, Stranger!

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

In this Discussion