improved KVStore

This commit is contained in:
Djeeberjr 2023-05-29 12:49:42 +02:00
parent dd2e9a4993
commit a343db133e

View File

@ -10,7 +10,7 @@ import haxe.ds.StringMap;
**/
class KVStore {
private var kvStore: StringMap<Dynamic> = new StringMap();
private final namespace:String;
public final namespace:String;
public function new(namespace: String) {
this.namespace = namespace;
@ -21,6 +21,11 @@ class KVStore {
FS.delete(nsFile);
}
public static function getStoreForClass(?pos:haxe.PosInfos) {
var className = pos.className;
return new KVStore(className);
}
private static function getNamespaceFile(namespace: String): String {
return '/var/ns/$namespace';
}
@ -50,8 +55,8 @@ class KVStore {
this.kvStore.set(key,value);
}
public inline function get<T>(key: String): Null<T> {
return this.kvStore.get(key);
public inline function get<T>(key: String,?orElse:T = null): Null<T> {
return this.kvStore.get(key) ?? orElse;
}
public inline function exists(key: String): Bool {