1

So I'm trying to use this library for caching. https://github.com/php-cache/array-adapter

This is the sample code from documentation.

$pool = new ArrayCachePool();
$item = $pool->getItem('key')->set('datakkk');
$pool->save($item);
dd($pool->get('key'));

I want to store the token for some 3 minutes and if that token expires I want to make an auth API call. If it is not expired it will call the whatever endpoint it has provided.

I have done most of the part just I'm stuck between how to cache the token. Because it does get stored when I call the above code but it gets cleared for the next API call. Tried singletone pattern but it's not working. Any help would be appreciated.

1 Answer 1

2

ArrayCache does not store any data between requests. It is supposed to store data during single script execution. So, when your script ends - all data from ArrayCache is lost.

To store data between requests use another cache engine, not ArrayCache.

Sign up to request clarification or add additional context in comments.

1 Comment

That totally makes sense. I was so confused about that. Thanks.

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.