Support the ongoing development of Laravel.io →
posted 8 years ago
Cache
Last updated 1 year ago.
0

Yes you can store the entire array in cache. It will be serialized and deserialized on request.

Documentation for more details :

https://laravel.com/docs/5.2/cache

0

So with cache, can i store this entire array?

Yes

// save the array using key-name of 'apidata' for 1 min
Cache::put( 'apidata', $ApiArray, 1 );

And then make it so if i run the request again it will go to the cache and fetch the data instead of actually sending the request?

Yes

// use cache if set
if ( Cache::has( 'apidata' ) ) {
    // get the apidata from the cache
    $ApiArray = Cache::get( 'apidata );
} else {
    // get the api data, how ever you are doing it ...
    $ApiArray = FetchAPI(); 

    // save in cache
    Cache::put( 'apidata', $ApiArray, 1 );
}



0

Sign in to participate in this thread!

Eventy

Your banner here too?

EnderPet enderpet Joined 24 Jan 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.