Skip to content

Commit

Permalink
Merge pull request #3 from SoapBox/change/prefix
Browse files Browse the repository at this point in the history
Add a prefix to the keys
  • Loading branch information
Justin Hayes authored Nov 7, 2018
2 parents 5e67e75 + d2d56cb commit 48fdb3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Idempotency.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private static function getCache(): Repository
*/
private static function getPrefix(): string
{
return config('idempotency.cache.prefix', '');
return 'idempotency:' . config('idempotency.cache.prefix', '');
}

/**
Expand Down
18 changes: 9 additions & 9 deletions tests/Unit/IdempotencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function adding_a_response_to_the_cache_caches_the_response_to_the_specif

Idempotency::add('unique-key', new Response());

$this->assertTrue(Cache::store('store1')->has('unique-key'));
$this->assertFalse(Cache::store('store2')->has('unique-key'));
$this->assertTrue(Cache::store('store1')->has('idempotency:unique-key'));
$this->assertFalse(Cache::store('store2')->has('idempotency:unique-key'));

Cache::store('store1')->flush();
Cache::store('store2')->flush();
Expand All @@ -35,8 +35,8 @@ public function adding_a_response_to_the_cache_caches_the_response_to_the_specif

Idempotency::add('unique-key', new Response());

$this->assertFalse(Cache::store('store1')->has('unique-key'));
$this->assertTrue(Cache::store('store2')->has('unique-key'));
$this->assertFalse(Cache::store('store1')->has('idempotency:unique-key'));
$this->assertTrue(Cache::store('store2')->has('idempotency:unique-key'));
}

/**
Expand All @@ -45,12 +45,12 @@ public function adding_a_response_to_the_cache_caches_the_response_to_the_specif
public function adding_a_response_to_the_cache_prefixes_the_key_with_the_prefix()
{
Idempotency::add('unique-key', new Response());
$this->assertTrue(Cache::has('unique-key'));
$this->assertTrue(Cache::has('idempotency:unique-key'));

config(['idempotency.cache.prefix' => 'prefix:']);

Idempotency::add('unique-key', new Response());
$this->assertTrue(Cache::has('prefix:unique-key'));
$this->assertTrue(Cache::has('idempotency:prefix:unique-key'));
}

/**
Expand All @@ -70,7 +70,7 @@ public function adding_a_response_to_the_cache_will_set_the_time_to_live_to_the_
});

Idempotency::add('unique-key', new Response());
$this->assertSame(60, Cache::store('test')->getTimeToLive('unique-key'));
$this->assertSame(60, Cache::store('test')->getTimeToLive('idempotency:unique-key'));
}

/**
Expand All @@ -87,15 +87,15 @@ public function adding_a_response_to_the_cache_will_set_the_time_to_live_to_a_da
});

Idempotency::add('unique-key', new Response());
$this->assertSame(1440, Cache::store('test')->getTimeToLive('unique-key'));
$this->assertSame(1440, Cache::store('test')->getTimeToLive('idempotency:unique-key'));
}

/**
* @test
*/
public function it_returns_with_null_when_trying_to_get_a_response_for_a_key_that_is_not_in_the_cache()
{
$this->assertNull(Idempotency::get('unique-key'));
$this->assertNull(Idempotency::get('idempotency:unique-key'));
}

/**
Expand Down

0 comments on commit 48fdb3e

Please sign in to comment.