KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Cache Array datasource - API response in Dashboard #3224

Open John opened this topic on on Jan 7 - 2 comments

John commented on Jan 7

Is there any way to cache an Array from API response in Dashboard? I made some trials on this (based on guidelines like https://www.koolreport.com/docs/dashboard/caching/) but i was unsuccesfull..

Sebastian Morales commented on Jan 8

I think Dashboard cache is only supported in sql database datasources for now. But you can imitate it in your API datasource using some code from PDOSource.php like this:

    protected function cache()
    {
        return \koolreport\dashboard\caching\FileCache::create(); //or MemCache, ApcCache
    }
    
    public function run()
    {
        ...
            $sql = $this->toQueryString(); // replace $sql here with your api call parameters
            $cache = $this->cache(); //your datasource cache
            if ($cache !== null) {
                $cache->name($this->name() . $cache->name()); //To be unqiue

                if ($this->owner !== null && $this->owner->hasProp("cache") === true && $this->owner->cache() !== null) {
                    $cache->ttl($this->owner->cache());
                }
                $store = $cache->get($sql);
                if ($store !== null) {
                    return $store;
                }
            } 
            //otherwise, if there's no cache setting or cache data, get data from api directly
            ...
John commented on Jan 9

Thanks, i'll try it!

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Cache