Skip to content

Commit b897406

Browse files
authored
Cache improvements (#447)
## Rationale Adjust to `Cache` API changes ## Related Pull Requests - LabKey/platform#8155
1 parent c03ca79 commit b897406

3 files changed

Lines changed: 15 additions & 21 deletions

File tree

‎Studies/src/org/labkey/studies/query/LookupSetsManager.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class LookupSetsManager
1616

1717
private LookupSetsManager()
1818
{
19-
_cache = CacheManager.getStringKeyCache(1000, CacheManager.UNLIMITED, "LookupSetsManagerCache");
19+
_cache = CacheManager.getCache(String.class, 1000, CacheManager.UNLIMITED, "LookupSetsManagerCache");
2020
}
2121

2222
public static LookupSetsManager get()

‎jbrowse/src/org/labkey/jbrowse/JBrowseFieldUtils.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
public class JBrowseFieldUtils
2525
{
26-
private static final Cache<String, Map<String, JBrowseFieldDescriptor>> _cache = CacheManager.getStringKeyCache(50000, CacheManager.DAY, "JBrowseFieldInfo");
26+
private static final Cache<String, Map<String, JBrowseFieldDescriptor>> _cache = CacheManager.getCache(String.class, 50000, CacheManager.DAY, "JBrowseFieldInfo");
2727

2828
private static final Logger _log = LogHelper.getLogger(JBrowseFieldUtils.class, "Logger for JBrowseFieldUtils");
2929

‎jbrowse/src/org/labkey/jbrowse/JBrowseLuceneSearch.java‎

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@
6565
import java.util.HashMap;
6666
import java.util.List;
6767
import java.util.Map;
68-
import java.util.Set;
6968
import java.util.StringTokenizer;
7069
import java.util.concurrent.ExecutorService;
7170
import java.util.concurrent.Executors;
7271
import java.util.function.Predicate;
7372
import java.util.regex.Matcher;
7473
import java.util.regex.Pattern;
74+
import java.util.stream.Stream;
7575

7676
import static org.labkey.jbrowse.JBrowseFieldUtils.VARIABLE_SAMPLES;
7777
import static org.labkey.jbrowse.JBrowseFieldUtils.getSession;
@@ -507,37 +507,33 @@ public static class LuceneIndexCache implements Cache<String, CacheEntry>
507507

508508
public LuceneIndexCache()
509509
{
510-
_cache = CacheManager.getStringKeyCache(1000, CacheManager.UNLIMITED, "JBrowseLuceneSearchCache");
510+
_cache = CacheManager.getCache(String.class, 1000, CacheManager.UNLIMITED, "JBrowseLuceneSearchCache");
511511

512512
}
513513

514514
@Override
515-
public void remove(@NotNull String key)
515+
public boolean remove(@NotNull String key)
516516
{
517517
CacheEntry e = get(key);
518-
_cache.remove(key);
518+
boolean ret = _cache.remove(key);
519519

520520
closeReader(e);
521+
522+
return ret;
521523
}
522524

523525
@Override
524526
public void clear()
525527
{
526-
for (String key : getKeys())
527-
{
528-
closeReader(get(key));
529-
}
528+
getKeys().forEach(key -> closeReader(get(key)));
530529

531530
_cache.clear();
532531
}
533532

534533
@Override
535534
public void close()
536535
{
537-
for (String key : getKeys())
538-
{
539-
closeReader(get(key));
540-
}
536+
getKeys().forEach(key -> closeReader(get(key)));
541537

542538
_cache.close();
543539
}
@@ -590,7 +586,7 @@ public int removeUsingFilter(Predicate<String> filter)
590586
}
591587

592588
@Override
593-
public Set<String> getKeys()
589+
public Stream<String> getKeys()
594590
{
595591
return _cache.getKeys();
596592
}
@@ -640,8 +636,7 @@ public File getLuceneIndexDir()
640636
public static JSONArray reportCacheInfo()
641637
{
642638
JSONArray cacheInfo = new JSONArray();
643-
for (String sessionId : _cache.getKeys())
644-
{
639+
_cache.getKeys().forEach(sessionId -> {
645640
LRUQueryCache qc = _cache.get(sessionId).getQueryCache();
646641
JSONObject info = new JSONObject();
647642
info.put("cacheSize", qc.getCacheSize());
@@ -651,7 +646,7 @@ public static JSONArray reportCacheInfo()
651646
info.put("evictionCount", qc.getEvictionCount());
652647
info.put("totalCount", qc.getTotalCount());
653648
cacheInfo.put(info);
654-
}
649+
});
655650

656651
return cacheInfo;
657652
}
@@ -677,14 +672,13 @@ public static void emptyCache()
677672

678673
public static void clearCacheForFile(@NotNull File luceneIndexDir)
679674
{
680-
for (String key : _cache.getKeys())
681-
{
675+
_cache.getKeys().forEach(key -> {
682676
CacheEntry entry = _cache.get(key);
683677
if (entry != null && luceneIndexDir.equals(entry.getLuceneIndexDir()))
684678
{
685679
_cache.remove(key);
686680
}
687-
}
681+
});
688682
}
689683

690684
public static void clearCache(@Nullable String jbrowseTrackId)

0 commit comments

Comments
 (0)