/** * * Attempts to retrieve as many of the required columns and ForeignKeyMaps as needed from * Memcache * * @return true if everything could be retrieved from the cache, or false if there remain columns to * retrieve. */ public Set<String> getCacheKeys() { // If the collection cannot provide a cache version, then it is not safe to cache columns // from this collection if (cacheVersion == 0) { LOGGER.severe(() -> this.formId + " has zero-valued version."); return Collections.emptySet(); } // Otherwise, try to retrieve all of the ColumnView and ForeignKeyMaps we need // from the Memcache service Set<String> toFetch = new HashSet<>(); for (FieldComponent fieldId : columnMap.keySet()) { toFetch.add(fieldCacheKey(fieldId)); } for (ForeignKeyId fk : foreignKeyMap.keySet()) { toFetch.add(fkCacheKey(fk)); } if (rowCount != null) { toFetch.add(rowCountKey()); } return toFetch; }
public Map<String, Object> getValuesToCache() { Map<String, Object> toPut = new HashMap<>(); for (Map.Entry<FieldComponent, PendingSlot<ColumnView>> column : columnMap.entrySet()) { ColumnView value; try { value = column.getValue().get(); } catch (IllegalStateException e) { throw new IllegalStateException(column.getKey().toString(), e); } toPut.put(fieldCacheKey(column.getKey()), value); } for (Map.Entry<ForeignKeyId, PendingSlot<ForeignKey>> fk : foreignKeyMap.entrySet()) { toPut.put(fkCacheKey(fk.getKey()), fk.getValue().get()); } if(!columnMap.isEmpty()) { toPut.put(rowCountKey(), rowCountFromColumn(columnMap)); } else if(rowCount != null) { toPut.put(rowCountKey(), rowCount.get()); } return toPut; }
ColumnView view = (ColumnView) cached.get(fieldCacheKey(fieldId)); if (view != null) {