Skip to content

Commit

Permalink
Changed the way cache is initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
kubagdynia committed Dec 4, 2023
1 parent 1548bae commit 3f1d68b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 0 additions & 2 deletions CacheDrive.Tests/MemoryAndFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,4 @@ public async Task CacheShouldExpired()
Assert.Fail();
}
}


}
27 changes: 25 additions & 2 deletions CacheDrive/Configuration/CacheSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,36 @@ namespace CacheDrive.Configuration;

public class CacheSettings
{
/// <summary>
/// Determines whether cache is enabled.
/// </summary>
public bool CacheEnabled { get; set; } = true;

public int CacheExpiration { get; set; } = 60;

/// <summary>
/// Cache folder name.
/// </summary>
public string CacheFolderName { get; set; } = "cache";

/// <summary>
/// In what units do we specify cache expiration.
/// </summary>
public CacheExpirationType CacheExpirationType { get; set; } = CacheExpirationType.Minutes;

/// <summary>
/// After what time the objects in the cache will expire. Based on CacheExpirationType.
/// </summary>
public int CacheExpiration { get; set; } = 60;

/// <summary>
/// Method of storing the cache.
/// Memory - only in memory.
/// MemoryAndFile - In memory while the application is running and in files after the application is closed.
/// </summary>
public CacheType CacheType { get; set; } = CacheType.Memory;

/// <summary>
/// Initialize cache automatically on startup.
/// Default value is true.
/// </summary>
public bool InitializeOnStartup { get; set; } = true;
}
8 changes: 8 additions & 0 deletions CacheDrive/Configuration/CacheType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ namespace CacheDrive.Configuration;

public enum CacheType
{
/// <summary>
/// Storing the cache only in memory.
/// </summary>
Memory,

/// <summary>
/// Storing the cache in memory while the application is running
/// and in files after the application is closed.
/// </summary>
MemoryAndFile
}
6 changes: 5 additions & 1 deletion CacheDrive/Services/MemoryCacheFileStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ public MemoryCacheFileStorageService(IOptions<CacheSettings> settings, IDateServ
: base(settings, dateService)
{
CreateCacheDirectory();
Initialize();

if (settings.Value.InitializeOnStartup)
{
Initialize();
}
}

~MemoryCacheFileStorageService()
Expand Down

0 comments on commit 3f1d68b

Please sign in to comment.