Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Caching and ORM
  • I'm looking for a neat way to use caching and the ORM but I can't figure it out. I'd like to use this sort structure: $posts = Model_Post::cache("posts")
    ->where('something',$something)
    ->get(); Where there's a method in the post class that tries to find the cached "posts", if it finds it it's returned, if not it retrieves it from the database and then caches it. Obviously this doesn't work, I just don't want to have to repeat the try/catch part everytime and repeating the key name. Any ideas?
  • Caching functionality for ORM is on the roadmap, but not for the upcoming v1.0 release. I would prefer a more low-level approach, where you just run your ORM code, and the ORM deals with retrieving data from cache. If you want to code it yourself, you can do that today using the Cache class.
  • Yes! This sounds good. What would you use as a naming convention for the keys? I guess you'd construct a key based on what you're looking for, and then in the get() and get_one() methods check to see if a cached version exists?
  • There already is a possibility, though not with method chaining. It turns out we forgot to document the Cache::call() method. Your example could also be done like this:
    $posts = Model_Post::find("all", array(
        'where' => array('something' => $something)
    ));
    

    Which you could use with Cache::call() like this:
    Cache::call('cache_name', array('Model_Post', 'find'), array("all", array(
        'where' => array('something' => $something)
    ));
    
  • Even i'm learning something new every day... I've added this method to the docs.
  • Jelmer Schreuder wrote on Wednesday 6th of July 2011:
    Which you could use with Cache::call() like this:
    Cache::call('cache_name', array('Model_Post', 'find'), array("all", array(
        'where' => array('something' => $something)
    ));
    

    This is perfect! Although I still like the idea of the ORM taking care of it. Thanks

Howdy, Stranger!

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

In this Discussion