Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public RaptorTransferIndex getRaptorTransfersForRequest(RouteRequest request) {
return transferCache.get(transfersByStopIndex, request);
}

public void initTransferCacheForRequest(RouteRequest request) {
transferCache.put(transfersByStopIndex, request);
}

public RaptorRequestTransferCache getTransferCache() {
return transferCache;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ public LoadingCache<CacheKey, RaptorTransferIndex> getTransferCache() {
return transferCache;
}

public void put(List<List<Transfer>> transfersByStopIndex, RouteRequest request) {
final CacheKey cacheKey = new CacheKey(transfersByStopIndex, request);
final RaptorTransferIndex raptorTransferIndex = RaptorTransferIndex.create(
transfersByStopIndex,
cacheKey.request
);

LOG.info("Initializing cache with request: {}", cacheKey.options);
transferCache.put(cacheKey, raptorTransferIndex);
}

public RaptorTransferIndex get(List<List<Transfer>> transfersByStopIndex, RouteRequest request) {
try {
return transferCache.get(
new CacheKey(
transfersByStopIndex,
StreetSearchRequestMapper.mapToTransferRequest(request).build()
)
);
return transferCache.get(new CacheKey(transfersByStopIndex, request));
} catch (ExecutionException e) {
throw new RuntimeException("Failed to get item from transfer cache", e);
}
Expand All @@ -53,7 +59,7 @@ private CacheLoader<CacheKey, RaptorTransferIndex> cacheLoader() {
@Override
@Nonnull
public RaptorTransferIndex load(@Nonnull CacheKey cacheKey) {
LOG.info("Adding request to cache: {}", cacheKey.options);
LOG.info("Adding runtime request to cache: {}", cacheKey.options);
return RaptorTransferIndex.create(cacheKey.transfersByStopIndex, cacheKey.request);
}
};
Expand All @@ -65,10 +71,10 @@ private static class CacheKey {
private final StreetSearchRequest request;
private final StreetRelevantOptions options;

private CacheKey(List<List<Transfer>> transfersByStopIndex, StreetSearchRequest request) {
private CacheKey(List<List<Transfer>> transfersByStopIndex, RouteRequest request) {
this.transfersByStopIndex = transfersByStopIndex;
this.request = request;
this.options = new StreetRelevantOptions(request);
this.request = StreetSearchRequestMapper.mapToTransferRequest(request).build();
this.options = new StreetRelevantOptions(this.request);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public static void initializeTransferCache(
LOG.info(progress.startMessage());

transferCacheRequests.forEach(request -> {
transitModel.getTransitLayer().getRaptorTransfersForRequest(request);
transitModel.getTransitLayer().initTransferCacheForRequest(request);

//noinspection Convert2MethodRef
progress.step(s -> LOG.info(s));
Expand Down