1

I use the file as cache driver and I want to cache the response from HTTP Client, but when I first time call a function everything works but when I call the function a second time to get data from cache I get this error

fseek(): Argument #1 ($stream) must be of type resource, int given

There is code I use for caching

public function manufacturers(){
   return Cache::remember('manufacturers', 10, function () {
      return Http::withoutVerifying()->post(config('api.systems').'Manufacturers/filter', [
          'showAll' => true
      ]);
   });
}

I tried other cache drivers and it works okay, I tried also to cache some other data instead of HTTP Client response and it also works fine.

1 Answer 1

2

From what I remember, the Cache::remember method is only able to cache simple data types such as strings and arrays. It is not able to cache a file resource like a response from the HTTP client. First, try to convert the response to a simpler data type before caching it.

public function manufacturers() {
   return Cache::remember('manufacturers', 10, function () {
      $response = Http::withoutVerifying()->post(config('api.systems').'Manufacturers/filter', [
          'showAll' => true
      ]);

      $json = $response->json();
      $data = JSON::decode($json);

      return $data;
   });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.