19 package org.sleuthkit.autopsy.discovery.search;
21 import com.google.common.cache.CacheBuilder;
22 import com.google.common.cache.LoadingCache;
23 import com.google.common.eventbus.Subscribe;
24 import java.util.Collections;
25 import java.util.List;
27 import java.util.Objects;
28 import java.util.concurrent.ExecutionException;
29 import java.util.concurrent.TimeUnit;
33 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
42 private static final LoadingCache<ArtifactCacheKey, Map<String, List<BlackboardArtifact>>>
cache
43 = CacheBuilder.newBuilder()
44 .maximumSize(MAXIMUM_CACHE_SIZE)
45 .expireAfterWrite(TIME_TO_LIVE, TimeUnit.MINUTES)
67 String typeName = request.getArtifactType().getLabel();
68 if (!typeName.startsWith(
"TSK_WEB")) {
69 throw new IllegalArgumentException(
"Only web artifacts are valid arguments. Type provided was " + typeName);
73 Map<String, List<BlackboardArtifact>> artifactsByDomain =
cache.get(
new ArtifactCacheKey(request));
74 final String normalizedDomain = request.getDomain().trim().toLowerCase();
75 return artifactsByDomain.getOrDefault(normalizedDomain, Collections.emptyList());
76 }
catch (ExecutionException ex) {
78 throw new DiscoveryException(
"Error fetching artifacts from cache for " + request.toString(), ex.getCause());
85 static class NewSearchListener {
89 cache.invalidateAll();
97 class ArtifactCacheKey {
99 private final ARTIFACT_TYPE type;
100 private final SleuthkitCase caseDatabase;
102 private ArtifactCacheKey(DomainSearchArtifactsRequest request) {
103 this.type = request.getArtifactType();
104 this.caseDatabase = request.getSleuthkitCase();
107 ARTIFACT_TYPE getType() {
111 SleuthkitCase getSleuthkitCase() {
112 return this.caseDatabase;
116 public int hashCode() {
118 hash = 67 * hash + Objects.hashCode(this.type);
119 hash = 67 * hash + Objects.hashCode(this.caseDatabase);
124 public boolean equals(Object obj) {
129 if (obj == null || getClass() != obj.getClass()) {
133 final ArtifactCacheKey other = (ArtifactCacheKey) obj;
136 return this.type == other.type &&
137 Objects.equals(this.caseDatabase, other.caseDatabase);
static EventBus getDiscoveryEventBus()
static final int MAXIMUM_CACHE_SIZE
static final NewSearchListener newSearchListener
static final int TIME_TO_LIVE
static final LoadingCache< ArtifactCacheKey, Map< String, List< BlackboardArtifact > > > cache