Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Add overrides to GeocodeLocations cache #603

Merged
merged 2 commits into from
Oct 22, 2020
Merged
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
8 changes: 6 additions & 2 deletions GeocodeLocations.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
Expand All @@ -22,13 +23,16 @@ public class GeocodeLocations : Module

// Cache responses for each location
private readonly ConcurrentDictionary<string, Task<CoordinateAbbreviated>> _coordinateCache =
new ConcurrentDictionary<string, Task<CoordinateAbbreviated>>();
new ConcurrentDictionary<string, Task<CoordinateAbbreviated>>(StringComparer.OrdinalIgnoreCase);

private readonly Config<string> _subscriptionKey;

public GeocodeLocations(Config<string> subscriptionKey)
{
_subscriptionKey = subscriptionKey.ThrowIfNull(nameof(subscriptionKey));

// Add coordinate overrides to cache
_coordinateCache["the netherlands"] = Task.FromResult(new CoordinateAbbreviated { Lat = 52.371807, Lon = 4.896029 });
}

protected override async Task<IEnumerable<IDocument>> ExecuteInputAsync(IDocument input, IExecutionContext context)
Expand Down