99namespace OCA \Settings \SetupChecks ;
1010
1111use OC \Memcache \Memcached ;
12+ use OCP \ICacheFactory ;
1213use OCP \IConfig ;
1314use OCP \IL10N ;
1415use OCP \IURLGenerator ;
@@ -20,6 +21,7 @@ public function __construct(
2021 private IL10N $ l10n ,
2122 private IConfig $ config ,
2223 private IURLGenerator $ urlGenerator ,
24+ private ICacheFactory $ cacheFactory ,
2325 ) {
2426 }
2527
@@ -56,6 +58,41 @@ public function run(): SetupResult {
5658 $ this ->urlGenerator ->linkToDocs ('admin-performance ' )
5759 );
5860 }
61+
62+ if ($ this ->cacheFactory ->isLocalCacheAvailable ()) {
63+ $ random = random_bytes (64 );
64+ $ local = $ this ->cacheFactory ->createLocal ('setupcheck.local ' );
65+ try {
66+ $ local ->set ('test ' , $ random );
67+ $ local2 = $ this ->cacheFactory ->createLocal ('setupcheck.local ' );
68+ $ actual = $ local2 ->get ('test ' );
69+ $ local ->remove ('test ' );
70+ } catch (\Throwable ) {
71+ $ actual = null ;
72+ }
73+
74+ if ($ actual !== $ random ) {
75+ return SetupResult::error ($ this ->l10n ->t ('Failed to write and read a value from local cache. ' ));
76+ }
77+ }
78+
79+ if ($ this ->cacheFactory ->isAvailable ()) {
80+ $ random = random_bytes (64 );
81+ $ distributed = $ this ->cacheFactory ->createDistributed ('setupcheck ' );
82+ try {
83+ $ distributed ->set ('test ' , $ random );
84+ $ distributed2 = $ this ->cacheFactory ->createDistributed ('setupcheck ' );
85+ $ actual = $ distributed2 ->get ('test ' );
86+ $ distributed ->remove ('test ' );
87+ } catch (\Throwable ) {
88+ $ actual = null ;
89+ }
90+
91+ if ($ actual !== $ random ) {
92+ return SetupResult::error ($ this ->l10n ->t ('Failed to write and read a value from distributed cache. ' ));
93+ }
94+ }
95+
5996 return SetupResult::success ($ this ->l10n ->t ('Configured ' ));
6097 }
6198}
0 commit comments