Determining if an Item Exists in the Cache

Problem

You want to see if a cached value exists.

Solution

Use Cache::has()

if (Cache::has('mykey'))
{
    echo "Yea! 'mykey' is cached!";
}

Discussion

Doesn't work with null items.

If you cache a null value, the Cache::has() method returns false.

Cache::put('test-null', null, 10);
if ( ! Cache::has('test-null'))
{
    echo "This line will always be output.";
}
comments powered by Disqus