MongolidLaravel\LaravelCacheComponent::has PHP Méthode

has() public méthode

Determine if an item exists in the cache. This method will also check if the ttl of the given cache key has been expired and will free the memory if so.
public has ( string $key ) : boolean
$key string Cache key of the item.
Résultat boolean Has cache key.
    public function has(string $key) : bool
    {
        return $this->laravelCache->has($key);
    }

Usage Example

 public function testShouldCheckIfHave()
 {
     // Set
     $cacheRepo = m::mock(Repository::class);
     $serializer = m::mock(Serializer::class);
     $component = new LaravelCacheComponent($cacheRepo, $serializer);
     $key = 'foo';
     $exists = true;
     // Expectations
     $cacheRepo->shouldReceive('has')->once()->with($key)->andReturn($exists);
     // Assertion
     $this->assertEquals($exists, $component->has($key));
 }
LaravelCacheComponent