public static RowCache fromString(String rowCache) { if (rowCache == null || rowCache.equalsIgnoreCase("none")) return new RowCache(Type.NONE, 0); else if (rowCache.equalsIgnoreCase("all")) return new RowCache(Type.ALL, Integer.MAX_VALUE); return new RowCache(Type.HEAD, Integer.parseInt(rowCache)); } public boolean isEnabled()
public String toThriftCellsPerRow() { if (rowCache.cacheFullPartitions()) return "ALL"; return String.valueOf(rowCache.rowsToCache); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; CachingOptions o2 = (CachingOptions) o; if (!keyCache.equals(o2.keyCache)) return false; if (!rowCache.equals(o2.rowCache)) return false; return true; }
if (metadata.getCaching().rowCache.cacheFullPartitions())
public static CachingOptions fromThrift(String caching, String cellsPerRow) throws ConfigurationException { RowCache rc = new RowCache(RowCache.Type.NONE); KeyCache kc = new KeyCache(KeyCache.Type.ALL); // if we get a caching string from thrift it is legacy, "ALL", "KEYS_ONLY" etc, fromString handles those if (caching != null) { CachingOptions givenOptions = CachingOptions.fromString(caching); rc = givenOptions.rowCache; kc = givenOptions.keyCache; } // if we get cells_per_row from thrift, it is either "ALL" or "<number of cells to cache>". if (cellsPerRow != null && rc.isEnabled()) rc = RowCache.fromString(cellsPerRow); return new CachingOptions(kc, rc); }
public boolean isRowCacheEnabled() { return metadata.getCaching().rowCache.isEnabled() && CacheService.instance.rowCache.getCapacity() > 0; }
@Override public int hashCode() { int result = keyCache.hashCode(); result = 31 * result + rowCache.hashCode(); return result; }
@Override public String toString() { return String.format("{\"keys\":\"%s\", \"rows_per_partition\":\"%s\"}", keyCache.toString(), rowCache.toString()); }
public static CachingOptions fromMap(Map<String, String> cacheConfig) throws ConfigurationException { validateCacheConfig(cacheConfig); if (!cacheConfig.containsKey("keys") && !cacheConfig.containsKey("rows_per_partition")) return CachingOptions.NONE; if (!cacheConfig.containsKey("keys")) return new CachingOptions(new KeyCache(KeyCache.Type.NONE), RowCache.fromString(cacheConfig.get("rows_per_partition"))); if (!cacheConfig.containsKey("rows_per_partition")) return CachingOptions.KEYS_ONLY; return new CachingOptions(KeyCache.fromString(cacheConfig.get("keys")), RowCache.fromString(cacheConfig.get("rows_per_partition"))); }