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
34 changes: 34 additions & 0 deletions SimcProfileParser.Tests/DataSync/CacheServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,39 @@ public void CS_Ptr_Defaults_Off()
// Assert
Assert.That(url, Is.EqualTo("https://raw.githubusercontent.com/simulationcraft/simc/test_branch/engine/dbc/generated/test.inc"));
}

[Test]
public async Task CS_ClearCache_Deletes_Files_And_Recovers()
{
// Arrange
CacheService cache = new CacheService(null, _loggerFactory.CreateLogger<CacheService>());

var configuration = new CacheFileConfiguration()
{
LocalParsedFile = "CombatRatingMultipliers.json",
ParsedFileType = SimcParsedFileType.CombatRatingMultipliers,
RawFiles = new Dictionary<string, string>()
{
{ "ScaleData.raw", "sc_scale_data" }
}
};
var filePath = Path.Combine(cache.BaseFileDirectory, "ScaleData.raw");

// Ensure a file exists by downloading it
_ = await cache.GetRawFileContentsAsync(configuration, "ScaleData.raw");
FileAssert.Exists(filePath);

// Act: clear the cache
await cache.ClearCacheAsync();

// Assert: file was deleted
Assert.That(File.Exists(filePath), Is.False, "Cache file should be removed after clear.");

// Act again: accessing should re-download
_ = await cache.GetRawFileContentsAsync(configuration, "ScaleData.raw");

// Assert: file is back
FileAssert.Exists(filePath);
}
}
}
22 changes: 22 additions & 0 deletions SimcProfileParser.Tests/SimcGenerationServiceIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,27 @@ public async Task SGS_Gets_Game_Version()
ClassicAssert.IsNotNull(version);
ClassicAssert.AreEqual("12.", version.Substring(0, 3));
}

[Test]
public async Task SGS_ClearsCache()
{
// Arrange: Warm up by generating something that touches the cache
var spellOptions = new SimcSpellOptions()
{
ItemLevel =226,
SpellId =343538,
ItemQuality = ItemQuality.ITEM_QUALITY_EPIC,
ItemInventoryType = InventoryType.INVTYPE_TRINKET
};
var spell = await _sgs.GenerateSpellAsync(spellOptions);
ClassicAssert.IsNotNull(spell);

// Act: clear the cache
await _sgs.ClearCacheAsync();

// Assert: call again should still work (re-hydrates cache)
var spell2 = await _sgs.GenerateSpellAsync(spellOptions);
ClassicAssert.IsNotNull(spell2);
}
}
}
29 changes: 29 additions & 0 deletions SimcProfileParser/DataSync/CacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,5 +501,34 @@ public void SetUseBranchName(string branchName)
{
_useBranchName = branchName;
}

public async Task ClearCacheAsync()
{
// Clear in-memory caches
_cachedFileData.Clear();
_eTagCacheData.Clear();

// Clear on-disk cache
try
{
if (Directory.Exists(BaseFileDirectory))
{
foreach (var file in Directory.GetFiles(BaseFileDirectory))
{
try { File.Delete(file); }
catch (Exception ex)
{
_logger?.LogWarning(ex, "Failed to delete cache file {file}", file);
}
}
}
}
catch (Exception ex)
{
_logger?.LogError(ex, "Error clearing cache directory {BaseFileDirectory}", BaseFileDirectory);
}

await Task.CompletedTask;
}
}
}
5 changes: 5 additions & 0 deletions SimcProfileParser/Interfaces/DataSync/ICacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,10 @@ public interface ICacheService
/// </summary>
/// <param name="branchName">e.g. thewarwithin</param>
void SetUseBranchName(string branchName);

/// <summary>
/// Clears all cached data from memory and disk.
/// </summary>
Task ClearCacheAsync();
}
}
5 changes: 5 additions & 0 deletions SimcProfileParser/Interfaces/ISimcGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public interface ISimcGenerationService
Task<SimcSpell> GenerateSpellAsync(SimcSpellOptions options);

Task<string> GetGameDataVersionAsync();

/// <summary>
/// Clears all cached data used by the generator (both memory and disk cache).
/// </summary>
Task ClearCacheAsync();
// TODO: Make this public once implemented.
//Task<List<SimcTalent>> GetAvailableTalentsAsync(int classId, int specId);
}
Expand Down
19 changes: 19 additions & 0 deletions SimcProfileParser/SimcGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,5 +477,24 @@ public string UseBranchName
get => _cacheService.UseBranchName;
set => _cacheService.SetUseBranchName(value);
}

/// <summary>
/// Clears the cached data for profiles, items, spells, and talents.
/// </summary>
/// <remarks>
/// <para>
/// This method will remove all cached entries associated with the current character or profile.
/// It is useful for refreshing data after game updates, profile changes, or debugging.
/// </para>
/// <para>
/// After clearing the cache, the next profile generation will
/// re-download and re-process all required data from SimulationCraft's data files.
/// </para>
/// </remarks>
/// <seealso cref="SimcProfileParser.Interfaces.ICacheService.ClearCacheAsync"/>
public async Task ClearCacheAsync()
{
await _cacheService.ClearCacheAsync();
}
}
}
6 changes: 3 additions & 3 deletions SimcProfileParser/SimcProfileParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<PropertyGroup>
<TargetFrameworks>net9.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>3.1.0</Version>
<AssemblyVersion>3.1.0</AssemblyVersion>
<FileVersion>3.1.0</FileVersion>
<Version>3.1.1</Version>
<AssemblyVersion>3.1.1</AssemblyVersion>
<FileVersion>3.1.1</FileVersion>
<Authors>Mechanical Priest</Authors>
<Company>Mechanical Priest</Company>
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
Expand Down