Skip to content

Commit

Permalink
Reduce local cache time and purge on update (#1286)
Browse files Browse the repository at this point in the history
  • Loading branch information
karashiiro authored Jul 18, 2024
1 parent c85190e commit 215ef27
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Universalis.DbAccess/MarketBoard/ListingStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private static readonly Counter
Prometheus.Metrics.CreateCounter("universalis_listing_local_cache_update", "");

private static readonly TimeSpan ListingsCacheTime = TimeSpan.FromMinutes(10);
private static readonly TimeSpan LocalListingsCacheTime = TimeSpan.FromSeconds(30);

private readonly ILogger<ListingStore> _logger;
private readonly ICacheRedisMultiplexer _cache;
Expand Down Expand Up @@ -85,6 +86,7 @@ public async Task DeleteLive(ListingQuery query, CancellationToken cancellationT
var db = _cache.GetDatabase(RedisDatabases.Cache.Listings);
var cacheKey = ListingsKey(query.WorldId, query.ItemId);
await db.KeyDeleteAsync(cacheKey);
await _easyCachingProvider.RemoveAsync(cacheKey, cancellationToken);
CachePurges.Inc();
}

Expand Down Expand Up @@ -168,6 +170,7 @@ INSERT INTO listing
var db = _cache.GetDatabase(RedisDatabases.Cache.Listings);
var cacheKey = ListingsKey(worldID, itemID);
await db.KeyDeleteAsync(cacheKey);
await _easyCachingProvider.RemoveAsync(cacheKey, cancellationToken);
CachePurges.Inc();
}
catch (Exception e)
Expand Down Expand Up @@ -425,7 +428,7 @@ await db.StringSetAsync(cacheKey, SerializeListings(listings), ListingsCacheTime
if (cacheValue.HasValue)
{
LocalCacheHits.Inc();
return (true, cacheValue.Value);
return (true, cacheValue.Value.OrderBy(listing => listing.PricePerUnit).ToList());
}
else
{
Expand All @@ -439,7 +442,7 @@ private async Task StoreListingsInLocalCache(int worldId, int itemId, IList<List
{
using var activity = Util.ActivitySource.StartActivity("ListingStore.StoreListingsInLocalCache");
var cacheKey = ListingsKey(worldId, itemId);
await _easyCachingProvider.SetAsync(cacheKey, listings, ListingsCacheTime, cancellationToken);
await _easyCachingProvider.SetAsync(cacheKey, listings, LocalListingsCacheTime, cancellationToken);
LocalCacheUpdates.Inc();
}

Expand Down

0 comments on commit 215ef27

Please sign in to comment.