private Map<MultiKey, List<Tag>> getTagCache() { if (tagCache == null) { tagCache = new CacheMap<MultiKey, List<Tag>>(); } return tagCache; }
/** * Check if the profile, whose username is given in input, has been cached by the profile cache * @param username the user name * @return true if the profile is in the cache */ public boolean isProfileCached(String username) { return profileCache.containsKey(username); }
/** * {@inheritDoc} */ public InterMineObject pilferObjectById(Integer id) { synchronized (cache) { return cache.get(id); } }
public void test2() throws Exception { CacheMap cm = new CacheMap(); cm.put(new Integer(5), new Integer(40)); cm.put(new Integer(763), new Integer(67)); cm.put(new Integer(2), null); assertEquals(new Integer(40), cm.get(new Integer(5))); assertEquals(new Integer(67), cm.get(new Integer(763))); assertNull(cm.get(new Integer(2))); assertTrue(cm.containsKey(new Integer(5))); assertTrue(cm.containsKey(new Integer(763))); assertTrue(cm.containsKey(new Integer(2))); assertNull(cm.remove(new Integer(3))); assertEquals(new Integer(40), cm.get(new Integer(5))); assertEquals(new Integer(67), cm.get(new Integer(763))); assertNull(cm.get(new Integer(2))); assertTrue(cm.containsKey(new Integer(5))); assertTrue(cm.containsKey(new Integer(763))); assertTrue(cm.containsKey(new Integer(2))); assertEquals(new Integer(40), cm.remove(new Integer(5))); assertNull(cm.get(new Integer(5))); assertEquals(new Integer(67), cm.get(new Integer(763))); assertNull(cm.get(new Integer(2))); assertFalse(cm.containsKey(new Integer(5))); assertTrue(cm.containsKey(new Integer(763))); assertTrue(cm.containsKey(new Integer(2)));
InterMineObject cached = null; synchronized (cache) { cached = cache.get(id); if (cached == null) { contains = cache.containsKey(id); cached = cache.get(id); if (cached == null) { contains = cache.containsKey(id);
/** * {@inheritDoc} */ public void invalidateObjectById(Integer id) { synchronized (cache) { cache.remove(id); } }
/** * {@inheritDoc} */ public Object cacheObjectById(Integer id, InterMineObject obj) { synchronized (cache) { cache.put(id, obj); } return obj; }
/** * Return a map from template name to template query containing superuser templates that are * tagged as public and are valid for the current data model. * @return a map from template name to template query */ public Map<String, ApiTemplate> getValidGlobalTemplates() { // TODO: We should likely also be using a cache for getAspectTemplates() // and getGlobalTemplates() synchronized (globalValidTemplateCache) { if (globalValidTemplateCache.isEmpty()) { Map<String, ApiTemplate> globalTemplates = getGlobalTemplates(); for (Map.Entry<String, ApiTemplate> entry : globalTemplates.entrySet()) { if (entry.getValue().isValid()) { globalValidTemplateCache.put(entry.getKey(), entry.getValue()); } } } return globalValidTemplateCache; } }
/** * {@inheritDoc} */ public void flushObjectById() { synchronized (cache) { cache.clear(); } }
/** * Constructs a new <tt>CacheMap</tt> with the same mappings as the * specified <tt>Map</tt>. The <tt>CacheMap</tt> is created with * default load factor, which is <tt>0.75</tt> and an initial capacity * sufficient to hold the mappings in the specified <tt>Map</tt>. * * @param t the map whose mappings are to be placed in this map. * @throws NullPointerException if the specified map is null. */ public CacheMap(Map<K, V> t) { subMap = new HashMap<K, Reference<Object>>(); this.name = "unknown"; putAll(t); } }
/** * {@inheritDoc} */ @Override public InterMineObject internalGetObjectById(Integer id, Class<? extends InterMineObject> clazz) throws ObjectStoreException { InterMineObject retval = super.internalGetObjectById(id, clazz); //Exception e = new Exception("internalGetObjectById called for " // + retval.getClass().toString() + " with id " + id); //e.fillInStackTrace(); //java.io.StringWriter sw = new java.io.StringWriter(); //java.io.PrintWriter pw = new java.io.PrintWriter(sw); //e.printStackTrace(pw); //pw.flush(); //LOG.error(sw.toString()); synchronized (cache) { Exception e = new Exception(); e.fillInStackTrace(); LOG.warn("Probable inefficiency: internalGetObjectById called " + (retval == null ? "" : "to fetch a " + Util.getFriendlyName(retval .getClass())) + " with id " + id + ", clazz " + clazz.toString() + ", cache size = " + cache.size() + " - maybe you should use" + " ObjectStoreFastCollectionsForTranslatorImpl", e); } internalGetObjectByIdCount++; if (internalGetObjectByIdCount % 1000 == 0) { LOG.info("internalGetObjectById run " + internalGetObjectByIdCount + " times"); } return retval; }
InterMineObject cached = null; synchronized (cache) { cached = cache.get(id); if (cached == null) { contains = cache.containsKey(id); cached = cache.get(id); if (cached == null) { contains = cache.containsKey(id);
/** * {@inheritDoc} */ public void invalidateObjectById(Integer id) { synchronized (cache) { cache.remove(id); } }
/** * {@inheritDoc} */ public Object cacheObjectById(Integer id, InterMineObject obj) { synchronized (cache) { cache.put(id, obj); } return obj; }
/** * Return a map from template name to template query containing superuser templates that are * tagged as public and are valid for the current data model. * @return a map from template name to template query */ public Map<String, ApiTemplate> getValidGlobalTemplates() { // TODO: We should likely also be using a cache for getAspectTemplates() // and getGlobalTemplates() synchronized (globalValidTemplateCache) { if (globalValidTemplateCache.isEmpty()) { Map<String, ApiTemplate> globalTemplates = getGlobalTemplates(); for (Map.Entry<String, ApiTemplate> entry : globalTemplates.entrySet()) { if (entry.getValue().isValid()) { globalValidTemplateCache.put(entry.getKey(), entry.getValue()); } } } return globalValidTemplateCache; } }
/** * Empty cache of global valid templates when these change. */ public void invalidateCache() { synchronized (globalValidTemplateCache) { globalValidTemplateCache.clear(); } }
/** * Constructs a new <tt>CacheMap</tt> with the same mappings as the * specified <tt>Map</tt>. The <tt>CacheMap</tt> is created with * default load factor, which is <tt>0.75</tt> and an initial capacity * sufficient to hold the mappings in the specified <tt>Map</tt>. * * @param t the map whose mappings are to be placed in this map. * @throws NullPointerException if the specified map is null. */ public CacheMap(Map<K, V> t) { subMap = new HashMap<K, Reference<Object>>(); this.name = "unknown"; putAll(t); } }
/** * {@inheritDoc} */ @Override public InterMineObject internalGetObjectById(Integer id, Class<? extends InterMineObject> clazz) throws ObjectStoreException { InterMineObject retval = super.internalGetObjectById(id, clazz); //Exception e = new Exception("internalGetObjectById called for " // + retval.getClass().toString() + " with id " + id); //e.fillInStackTrace(); //java.io.StringWriter sw = new java.io.StringWriter(); //java.io.PrintWriter pw = new java.io.PrintWriter(sw); //e.printStackTrace(pw); //pw.flush(); //LOG.error(sw.toString()); synchronized (cache) { Exception e = new Exception(); e.fillInStackTrace(); LOG.warn("Probable inefficiency: internalGetObjectById called " + (retval == null ? "" : "to fetch a " + Util.getFriendlyName(retval .getClass())) + " with id " + id + ", clazz " + clazz.toString() + ", cache size = " + cache.size() + " - maybe you should use" + " ObjectStoreFastCollectionsForTranslatorImpl", e); } internalGetObjectByIdCount++; if (internalGetObjectByIdCount % 1000 == 0) { LOG.info("internalGetObjectById run " + internalGetObjectByIdCount + " times"); } return retval; }
/** * Get a user's Profile using an ID * @param id userprofile ID * @return user's profile */ public Profile getProfile(int id) { Map<String, List<FieldDescriptor>> classKeys = getClassKeys(os.getModel()); UserProfile up; try { up = (UserProfile) uosw.getObjectById(id, UserProfile.class); } catch (ObjectStoreException e) { throw new RuntimeException("Error retrieving profile", e); } if (up != null && profileCache.containsKey(up.getUsername())) { return profileCache.get(up.getUsername()); } return wrapUserProfile(up, classKeys); }
/** * Constructor for this object. */ public OptimiserCache() { cacheLines = new CacheMap<String, Set<OptimiserCacheLine>>(); }