Reputation: 1238
I am storing value in Cache
but when i try to get value from cache
it returns null
function storeIds(Request $request){
$items="120,130,140,150";
Cache::put('Ids', $items, 55);
return response()->json(['success' => true], 200);
}
function getIds(){
$ids = Cache::get('Ids');
var_dump($ids); //null
}
I'm storing cache value to one function and try to access another function but not able to get null
value
I have set CACHE_DRIVER=array
.env file of laravel project
Can I change Cache driver runtime?
Upvotes: 2
Views: 1343
Reputation: 638
You used array cache driver, it doesn't persist data and it stores the item in php array just for testing. for array driver, you can put and get cache key in the same request.
recommendation for using cache driver:
Development
Production
Redis
Memcached
Upvotes: 1
Reputation: 7242
Yes, you can set and get Cache driver runtime.
SET
Cache::store('file')->put('Ids', $items, 55);
GET
Cache::store('file')->get('Ids');
Upvotes: 2