2
2
3
3
namespace Leantime \Core \Providers ;
4
4
5
+ use Illuminate \Cache \MemcachedConnector ;
5
6
use Illuminate \Support \ServiceProvider ;
7
+ use Leantime \Core \AppSettings ;
8
+ use Leantime \Core \CliRequest ;
9
+ use Leantime \Core \Events ;
10
+ use Leantime \Core \IncomingRequest ;
11
+ use Leantime \Domain \Setting \Services \Setting as SettingsService ;
6
12
7
13
class Cache extends ServiceProvider
8
14
{
@@ -13,14 +19,88 @@ class Cache extends ServiceProvider
13
19
*/
14
20
public function register ()
15
21
{
22
+
23
+ /**
24
+ * @todo the following should eventually automatically turn caches into redis if available,
25
+ * then memcached if available,
26
+ * then fileStore
27
+ */
28
+ $ this ->app ->singleton (\Illuminate \Cache \CacheManager::class, function ($ app ) {
29
+
30
+ //installation cache is per server
31
+ $ this ->app ['config ' ]['cache.stores.installation ' ] = [
32
+ 'driver ' => 'file ' ,
33
+ 'connection ' => 'default ' ,
34
+ 'path ' => APP_ROOT . '/cache/installation ' ,
35
+ ];
36
+
37
+ //Instance is per company id
38
+ $ instanceStore = fn () =>
39
+ $ this ->app ['config ' ]['cache.stores.instance ' ] = [
40
+ 'driver ' => 'file ' ,
41
+ 'connection ' => 'default ' ,
42
+ 'path ' => APP_ROOT . "/cache/ " . $ this ->app ->make (SettingsService::class)->getCompanyId (),
43
+ ];
44
+
45
+ if ($ this ->app ->make (IncomingRequest::class) instanceof CliRequest) {
46
+ if (empty ($ this ->app ->make (SettingsService::class)->getCompanyId ())) {
47
+ throw new \RuntimeException ('You can \'t run this CLI command until you have installed Leantime. ' );
48
+ }
49
+
50
+ $ instanceStore ();
51
+ } else {
52
+ //Initialize instance cache store only after install was successfull
53
+ Events::add_event_listener (
54
+ 'leantime.core.middleware.installed.handle.after_install ' ,
55
+ function () use ($ instanceStore ) {
56
+ if (! session ("isInstalled " )) {
57
+ return ;
58
+ }
59
+ $ instanceStore ();
60
+ }
61
+ );
62
+ }
63
+
64
+ $ cacheManager = new \Illuminate \Cache \CacheManager ($ app );
65
+
66
+ $ cacheManager ->setDefaultDriver ('instance ' );
67
+
68
+ return $ cacheManager ;
69
+ });
70
+ $ this ->app ->singleton ('cache.store ' , fn ($ app ) => $ app ['cache ' ]->driver ());
71
+ $ this ->app ->singleton ('cache.psr6 ' , fn ($ app ) => new \Symfony \Component \Cache \Adapter \Psr16Adapter ($ app ['cache.store ' ]));
72
+ $ this ->app ->singleton ('memcached.connector ' , fn () => new MemcachedConnector ());
73
+
74
+
75
+ $ this ->app ->alias (\Illuminate \Cache \CacheManager::class, 'cache ' );
76
+ $ this ->app ->alias (\Illuminate \Cache \CacheManager::class, \Illuminate \Contracts \Cache \Factory::class);
77
+
78
+ }
79
+
80
+ public function boot () {
81
+
82
+
83
+
84
+ $ currentVersion = $ this ->app ->make (AppSettings::class)->appVersion ;
85
+ $ cachedVersion = \Illuminate \Support \Facades \Cache::store ('installation ' )->rememberForever ('version ' , fn () => $ currentVersion );
86
+
87
+ if ($ currentVersion == $ cachedVersion ) {
88
+ return ;
89
+ }
90
+
91
+ \Illuminate \Support \Facades \Cache::store ('installation ' )->flush ();
92
+
16
93
}
17
94
18
95
/**
19
96
* Manages the instance cache.
20
97
*
21
98
* @return void
22
99
*/
23
- private function instanceCacheManager ()
100
+ public function checkCacheVersion (): void
24
101
{
102
+
103
+
25
104
}
105
+
26
106
}
0 commit comments