import java.lang.ref.WeakReference;
import java.util.HashMap;
+import java.util.HashSet;
public class ObjectCache<T extends IdCachable> {
HashMap<Integer, WeakReference<T>> hashmap = new HashMap<>();
+ private static HashSet<ObjectCache<?>> caches = new HashSet<>();
+
+ protected ObjectCache() {
+ caches.add(this);
+ }
+
public void put(T c) {
hashmap.put(c.getId(), new WeakReference<T>(c));
}
}
return null;
}
+
+ public static void clearAllCashes() {
+ for (ObjectCache<?> objectCache : caches) {
+ objectCache.hashmap.clear();
+ }
+ }
}
import org.cacert.gigi.GigiApiException;
import org.cacert.gigi.dbObjects.EmailAddress;
+import org.cacert.gigi.dbObjects.ObjectCache;
import org.cacert.gigi.dbObjects.User;
import org.cacert.gigi.localisation.Language;
import org.cacert.gigi.testUtils.ManagedTest;
@Test
public void testMailSetDefaultWeb() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
+ ObjectCache.clearAllCashes();
EmailAddress adrr = createVerifiedEmail(u);
assertNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + adrr.getId()));
assertEquals(User.getById(u.getId()).getEmail(), adrr.getAddress());