22
33namespace MintyPHP ;
44
5+ use Memcached ;
6+
57class Cache
68{
7- public static $ prefix = 'mintyphp ' ;
8- public static $ servers = '127.0.0.1 ' ;
9+ public static string $ prefix = 'mintyphp ' ;
10+ public static string $ servers = '127.0.0.1 ' ;
911
1012 /**
11- * @var \ Memcached
13+ * @var ? Memcached
1214 */
1315 protected static $ memcache = null ;
1416
1517 protected static function initialize (): void
1618 {
17- if (!static ::$ memcache ) {
18- static ::$ memcache = new \ Memcached ();
19- $ servers = explode (', ' , static ::$ servers );
19+ if (!self ::$ memcache ) {
20+ self ::$ memcache = new Memcached ();
21+ $ servers = explode (', ' , self ::$ servers );
2022 $ servers = array_map (function ($ server ) {
2123 $ server = explode (': ' , trim ($ server ));
2224 if (count ($ server ) == 1 ) $ server [1 ] = '11211 ' ;
@@ -56,8 +58,8 @@ protected static function variable(mixed $var): string
5658 public static function add (string $ key , mixed $ var , int $ expire = 0 ): bool
5759 {
5860 if (Debugger::$ enabled ) $ time = microtime (true );
59- if (!static ::$ memcache ) static ::initialize ();
60- $ res = static ::$ memcache ->add (static ::$ prefix . $ key , $ var , $ expire );
61+ if (!self ::$ memcache ) self ::initialize ();
62+ $ res = self ::$ memcache ->add (self ::$ prefix . $ key , $ var , $ expire );
6163 if (Debugger::$ enabled ) {
6264 $ duration = microtime (true ) - $ time ;
6365 $ command = 'add ' ;
@@ -69,7 +71,7 @@ public static function add(string $key, mixed $var, int $expire = 0): bool
6971 return $ res ;
7072 }
7173
72- public static function decrement (string $ key , int $ value = 1 ): int
74+ public static function decrement (string $ key , int $ value = 1 ): int | false
7375 {
7476 if (Debugger::$ enabled ) $ time = microtime (true );
7577 if (!self ::$ memcache ) self ::initialize ();
@@ -115,7 +117,7 @@ public static function get(string $key): mixed
115117 return $ res ;
116118 }
117119
118- public static function increment (string $ key , int $ value = 1 ): int
120+ public static function increment (string $ key , int $ value = 1 ): int | false
119121 {
120122 if (Debugger::$ enabled ) $ time = microtime (true );
121123 if (!self ::$ memcache ) self ::initialize ();
@@ -134,8 +136,8 @@ public static function increment(string $key, int $value = 1): int
134136 public static function replace (string $ key , mixed $ var , int $ expire = 0 ): bool
135137 {
136138 if (Debugger::$ enabled ) $ time = microtime (true );
137- if (!static ::$ memcache ) static ::initialize ();
138- $ res = static ::$ memcache ->replace (static ::$ prefix . $ key , $ var , $ expire );
139+ if (!self ::$ memcache ) self ::initialize ();
140+ $ res = self ::$ memcache ->replace (self ::$ prefix . $ key , $ var , $ expire );
139141 if (Debugger::$ enabled ) {
140142 $ duration = microtime (true ) - $ time ;
141143 $ command = 'replace ' ;
@@ -150,8 +152,8 @@ public static function replace(string $key, mixed $var, int $expire = 0): bool
150152 public static function set (string $ key , mixed $ var , int $ expire = 0 ): bool
151153 {
152154 if (Debugger::$ enabled ) $ time = microtime (true );
153- if (!static ::$ memcache ) static ::initialize ();
154- $ res = static ::$ memcache ->set (static ::$ prefix . $ key , $ var , $ expire );
155+ if (!self ::$ memcache ) self ::initialize ();
156+ $ res = self ::$ memcache ->set (self ::$ prefix . $ key , $ var , $ expire );
155157 if (Debugger::$ enabled ) {
156158 $ duration = microtime (true ) - $ time ;
157159 $ command = 'set ' ;
0 commit comments