подправил кеширование отображаемых данных ( чтобы не распаковывать каждый раз список имен групп и прочее)
This commit is contained in:
46
src/Common/UI/VisualCache/VisualCaches.java
Normal file
46
src/Common/UI/VisualCache/VisualCaches.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package Common.UI.VisualCache;
|
||||
import Common.Database.DBObject;
|
||||
import TestingSystem.Common.Configuration.Configuration;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
public class VisualCaches {
|
||||
static LinkedHashMap<Class, LinkedHashMap<Object, VisualCache>> allData = new LinkedHashMap<>();
|
||||
static LinkedHashMap<Object, VisualCache> getDataForClass(Class class_) {
|
||||
LinkedHashMap<Object, VisualCache> data;
|
||||
if (allData.containsKey(class_)) {
|
||||
data = allData.get(class_);
|
||||
} else {
|
||||
data = new LinkedHashMap<>();
|
||||
allData.put(class_, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
//чтобы не трогать сами объекты и не сбить сериализацию
|
||||
static VisualCache createCache(Object object) {
|
||||
if (object instanceof Configuration)
|
||||
return new ConfigurationCache((Configuration) object);
|
||||
return new VisualCache();
|
||||
}
|
||||
public static VisualCache GetCache(DBObject object) {
|
||||
// System.out.println("get visual cache for " + object.getPK());
|
||||
VisualCache res = null;
|
||||
LinkedHashMap<Object, VisualCache> data = getDataForClass(object.getClass());
|
||||
if (!data.containsKey(object.getPK())) {
|
||||
// System.out.println("cache not found, creating...");
|
||||
data.put(object.getPK(), res = createCache(object));
|
||||
} else {
|
||||
// System.out.println("cache found");
|
||||
res = data.get(object.getPK());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public static void DeleteCahce(DBObject object){
|
||||
DeleteCahce(object.getClass(), object.getPK());
|
||||
}
|
||||
public static void DeleteCahce(Class class_, Object pk){
|
||||
LinkedHashMap<Object, VisualCache> data = getDataForClass(class_);
|
||||
if (data.containsKey(pk))
|
||||
data.remove(pk);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user