Skip to content

Commit ab87f49

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

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ extends `Illuminate\Foundation\Auth\User`. Overriding that would break functiona
7474
Not only that, but it probably isn't a good idea to cache the user model anyway,
7575
since you always want to pull the most up-to-date info on it.
7676

77+
### Multitenant support for cached models
78+
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.
79+
80+
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.
81+
An example in the context of using the hyn/multi-tenant package can be:
82+
```php
83+
public function getCachePrefix()
84+
{
85+
return $this->getConnectionName() . '-' . $this->getConnection()->getDatabaseName();
86+
}
87+
```
88+
7789
### Optional Disabling Caching of Queries
7890
**Recommendation: add this to all your seeder queries to avoid pulling in
7991
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)