forked from archtechx/tenancy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for global cache (archtechx#78)
- Loading branch information
Showing
5 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Stancl\Tenancy; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class GlobalCacheFacade extends Facade | ||
{ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'globalCache'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Stancl\Tenancy\Tests; | ||
|
||
use GlobalCache; | ||
|
||
class GlobalCacheTest extends TestCase | ||
{ | ||
public $autoCreateTenant = false; | ||
public $autoInitTenancy = false; | ||
|
||
/** @test */ | ||
public function global_cache_manager_stores_data_in_global_cache() | ||
{ | ||
$this->assertSame(null, cache('foo')); | ||
GlobalCache::put(['foo' => 'bar'], 1); | ||
$this->assertSame('bar', GlobalCache::get('foo')); | ||
|
||
tenant()->create('foo.localhost'); | ||
tenancy()->init('foo.localhost'); | ||
$this->assertSame('bar', GlobalCache::get('foo')); | ||
|
||
GlobalCache::put(['abc' => 'xyz'], 1); | ||
cache(['def' => 'ghi'], 1); | ||
$this->assertSame('ghi', cache('def')); | ||
|
||
tenancy()->end(); | ||
$this->assertSame('xyz', GlobalCache::get('abc')); | ||
$this->assertSame('bar', GlobalCache::get('foo')); | ||
$this->assertSame(null, cache('def')); | ||
|
||
tenant()->create('bar.localhost'); | ||
tenancy()->init('bar.localhost'); | ||
$this->assertSame('xyz', GlobalCache::get('abc')); | ||
$this->assertSame('bar', GlobalCache::get('foo')); | ||
$this->assertSame(null, cache('def')); | ||
cache(['def' => 'xxx'], 1); | ||
$this->assertSame('xxx', cache('def')); | ||
|
||
tenancy()->init('foo.localhost'); | ||
$this->assertSame('ghi', cache('def')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters