Skip to content

Commit 9f98741

Browse files
- update README.md
1 parent 898bb67 commit 9f98741

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ relationships. This package is an attempt to address those requirements.
2121
- automatic, self-invalidating model query caching.
2222
- automatic use of cache tags for cache providers that support them (will
2323
flush entire cache for providers that don't).
24+
- support for multitenant implementations by implementing getCachePrefix method in the Model class
2425

2526
## Requirements
2627
- PHP >= 7.1.3
@@ -74,6 +75,18 @@ extends `Illuminate\Foundation\Auth\User`. Overriding that would break functiona
7475
Not only that, but it probably isn't a good idea to cache the user model anyway,
7576
since you always want to pull the most up-to-date info on it.
7677

78+
### Multitenant support for cached models
79+
If you need multitenancy support the same model context (key and tags) needs to be cached for each denant with it's specific values. This requires a separations of cache that is supported by implementing the getCachePrefix method in the model class.
80+
81+
I would recommend to implement in your application a TenantCachable trait containing the getCachePrefix method that for example returns a unique value corresponding to each tenant.
82+
An example in the context of using the hyn/multi-tenant package can be:
83+
```php
84+
public function getCachePrefix()
85+
{
86+
return $this->getConnectionName() . '-' . $this->getConnection()->getDatabaseName();
87+
}
88+
```
89+
7790
### Optional Disabling Caching of Queries
7891
**Recommendation: add this to all your seeder queries to avoid pulling in
7992
cached information when reseeding multiple times.**

src/CacheGlobal.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php namespace GeneaLabs\LaravelModelCaching;
2+
3+
class CacheGlobal
4+
{
5+
protected static $enabled = true;
6+
7+
public static function disableCache()
8+
{
9+
static::$enabled = false;
10+
}
11+
12+
public static function enableCache()
13+
{
14+
static::$enabled = true;
15+
}
16+
17+
public static function isDisabled()
18+
{
19+
return !static::$enabled;
20+
}
21+
22+
public static function isEnabled()
23+
{
24+
return static::$enabled;
25+
}
26+
}

0 commit comments

Comments
 (0)