Skip to content

Commit

Permalink
Remove the tax rates cache
Browse files Browse the repository at this point in the history
  • Loading branch information
karashiiro committed Aug 8, 2024
1 parent 61b4477 commit 66fce69
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions src/Universalis.DbAccess/MarketBoard/TaxRatesStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ namespace Universalis.DbAccess.MarketBoard;
public class TaxRatesStore : ITaxRatesStore
{
private readonly IPersistentRedisMultiplexer _redis;
private readonly ICacheRedisMultiplexer _cache;
private readonly ILogger<TaxRatesStore> _logger;

public TaxRatesStore(IPersistentRedisMultiplexer redis, ICacheRedisMultiplexer cache, ILogger<TaxRatesStore> logger)
public TaxRatesStore(IPersistentRedisMultiplexer redis, ILogger<TaxRatesStore> logger)
{
_redis = redis;
_cache = cache;
_logger = logger;
}

Expand All @@ -26,37 +24,17 @@ public async Task SetTaxRates(int worldId, TaxRates taxRates)

// Store data in the database
var db = _redis.GetDatabase(RedisDatabases.Instance0.TaxRates);
var dbTask = StoreTaxRates(db, taxRates, worldId);

// Write through to the cache
var cache = _cache.GetDatabase(RedisDatabases.Cache.TaxRates);
var cacheTask = StoreTaxRates(cache, taxRates, worldId);

await Task.WhenAll(dbTask, cacheTask);
await StoreTaxRates(db, taxRates, worldId);
}

public async Task<TaxRates> GetTaxRates(int worldId)
{
using var activity = Util.ActivitySource.StartActivity("TaxRatesStore.GetTaxRates");

// Try to retrieve data from the cache
var cache = _cache.GetDatabase(RedisDatabases.Cache.TaxRates);
if (await HasTaxRates(cache, worldId))
{
var cachedObject = await FetchTaxRates(cache, worldId);
if (cachedObject != null)
{
return cachedObject;
}
}

// Fetch the tax rates from the database
var db = _redis.GetDatabase(RedisDatabases.Instance0.TaxRates);
var taxRates = await FetchTaxRates(db, worldId);

// Store the result in the cache
await StoreTaxRates(cache, taxRates, worldId);

return taxRates;
}

Expand Down

0 comments on commit 66fce69

Please sign in to comment.