diff --git a/CommunityToolkit.Uwp.Graph.Controls/CommunityToolkit.Uwp.Graph.Controls.csproj b/CommunityToolkit.Uwp.Graph.Controls/CommunityToolkit.Uwp.Graph.Controls.csproj
index a4a3235..a03d153 100644
--- a/CommunityToolkit.Uwp.Graph.Controls/CommunityToolkit.Uwp.Graph.Controls.csproj
+++ b/CommunityToolkit.Uwp.Graph.Controls/CommunityToolkit.Uwp.Graph.Controls.csproj
@@ -16,7 +16,7 @@
UWP Toolkit Windows Controls MSAL Microsoft Graph AadLogin ProfileCard Person PeoplePicker Login
false
true
- 8.0
+ 9.0
Debug;Release;CI
AnyCPU;ARM;ARM64;x64;x86
diff --git a/CommunityToolkit.Uwp.Graph.Controls/Helpers/RoamingSettings/BaseRoamingSettingsDataStore.cs b/CommunityToolkit.Uwp.Graph.Controls/Helpers/RoamingSettings/BaseRoamingSettingsDataStore.cs
index 137fb53..b3109d1 100644
--- a/CommunityToolkit.Uwp.Graph.Controls/Helpers/RoamingSettings/BaseRoamingSettingsDataStore.cs
+++ b/CommunityToolkit.Uwp.Graph.Controls/Helpers/RoamingSettings/BaseRoamingSettingsDataStore.cs
@@ -33,7 +33,7 @@ public abstract class BaseRoamingSettingsDataStore : IRoamingSettingsDataStore
public string UserId { get; }
///
- public IDictionary Cache { get; private set; }
+ public IDictionary Cache { get; private set; } = new Dictionary();
///
/// Gets an object serializer for converting objects in the data store.
@@ -53,8 +53,6 @@ public BaseRoamingSettingsDataStore(string userId, string dataStoreId, IObjectSe
Id = dataStoreId;
UserId = userId;
Serializer = objectSerializer;
-
- Cache = null;
}
///
@@ -76,7 +74,7 @@ public BaseRoamingSettingsDataStore(string userId, string dataStoreId, IObjectSe
/// True if a value exists.
public bool KeyExists(string key)
{
- return Cache != null && Cache.ContainsKey(key);
+ return Cache?.ContainsKey(key) ?? false;
}
///
@@ -150,8 +148,6 @@ public T Read(string compositeKey, string key, T @default = default)
/// Type of object saved.
public void Save(string key, T value)
{
- InitCache();
-
// Update the cache
Cache[key] = SerializeValue(value);
@@ -174,8 +170,6 @@ public void Save(string key, T value)
/// Type of object saved.
public void Save(string compositeKey, IDictionary values)
{
- InitCache();
-
var type = typeof(T);
var typeInfo = type.GetTypeInfo();
@@ -255,23 +249,12 @@ public void Save(string compositeKey, IDictionary values)
///
public abstract Task Sync();
- ///
- /// Initialize the internal cache.
- ///
- protected void InitCache()
- {
- if (Cache == null)
- {
- Cache = new Dictionary();
- }
- }
-
///
/// Delete the internal cache.
///
protected void DeleteCache()
{
- Cache = null;
+ Cache.Clear();
}
///
diff --git a/CommunityToolkit.Uwp.Graph.Controls/Helpers/RoamingSettings/OneDriveDataStore.cs b/CommunityToolkit.Uwp.Graph.Controls/Helpers/RoamingSettings/OneDriveDataStore.cs
index 14f723a..c3b7063 100644
--- a/CommunityToolkit.Uwp.Graph.Controls/Helpers/RoamingSettings/OneDriveDataStore.cs
+++ b/CommunityToolkit.Uwp.Graph.Controls/Helpers/RoamingSettings/OneDriveDataStore.cs
@@ -65,8 +65,6 @@ public OneDriveDataStore(string userId, string syncDataFileName, IObjectSerializ
///
public override Task Create()
{
- InitCache();
-
return Task.CompletedTask;
}
@@ -74,7 +72,7 @@ public override Task Create()
public override async Task Delete()
{
// Clear the cache
- DeleteCache();
+ Cache.Clear();
// Delete the remote.
await Delete(UserId, Id);
@@ -122,11 +120,6 @@ public override async Task Sync()
bool needsUpdate = false;
if (remoteData != null)
{
- if (remoteData.Keys.Count > 0)
- {
- InitCache();
- }
-
// Update local cache with additions from remote
foreach (string key in remoteData.Keys.ToList())
{
@@ -138,7 +131,7 @@ public override async Task Sync()
}
}
}
- else if (Cache != null && Cache.Count > 0)
+ else if (Cache.Count > 0)
{
// The remote does not yet exist, and we have data to save.
needsUpdate = true;
diff --git a/CommunityToolkit.Uwp.Graph.Controls/Helpers/RoamingSettings/UserExtensionDataStore.cs b/CommunityToolkit.Uwp.Graph.Controls/Helpers/RoamingSettings/UserExtensionDataStore.cs
index 0fde3df..ff4d884 100644
--- a/CommunityToolkit.Uwp.Graph.Controls/Helpers/RoamingSettings/UserExtensionDataStore.cs
+++ b/CommunityToolkit.Uwp.Graph.Controls/Helpers/RoamingSettings/UserExtensionDataStore.cs
@@ -107,8 +107,6 @@ public UserExtensionDataStore(string userId, string extensionId, IObjectSerializ
/// The newly created Extension object.
public override async Task Create()
{
- InitCache();
-
await Create(UserId, Id);
}
@@ -119,7 +117,7 @@ public override async Task Create()
public override async Task Delete()
{
// Delete the cache
- DeleteCache();
+ Cache.Clear();
// Delete the remote.
await Delete(UserId, Id);
@@ -164,8 +162,6 @@ public override async Task Sync()
if (remoteData != null)
{
- InitCache();
-
// Update local cache with additions from remote
foreach (string key in remoteData.Keys.ToList())
{
diff --git a/UnitTests/UnitTests.UWP/RoamingSettings/Test_OneDriveDataStore.cs b/UnitTests/UnitTests.UWP/RoamingSettings/Test_OneDriveDataStore.cs
index 0e46dc4..0635706 100644
--- a/UnitTests/UnitTests.UWP/RoamingSettings/Test_OneDriveDataStore.cs
+++ b/UnitTests/UnitTests.UWP/RoamingSettings/Test_OneDriveDataStore.cs
@@ -37,7 +37,7 @@ void test()
// Evaluate the default state is as expected
Assert.IsFalse(dataStore.AutoSync);
- Assert.IsNull(dataStore.Cache);
+ Assert.IsNotNull(dataStore.Cache);
Assert.AreEqual(dataStoreId, dataStore.Id);
Assert.AreEqual(userId, dataStore.UserId);
diff --git a/UnitTests/UnitTests.UWP/RoamingSettings/Test_UserExtensionDataStore.cs b/UnitTests/UnitTests.UWP/RoamingSettings/Test_UserExtensionDataStore.cs
index c4160cb..28d2f12 100644
--- a/UnitTests/UnitTests.UWP/RoamingSettings/Test_UserExtensionDataStore.cs
+++ b/UnitTests/UnitTests.UWP/RoamingSettings/Test_UserExtensionDataStore.cs
@@ -37,7 +37,7 @@ void test()
// Evaluate the default state is as expected
Assert.IsFalse(dataStore.AutoSync);
- Assert.IsNull(dataStore.Cache);
+ Assert.IsNotNull(dataStore.Cache);
Assert.AreEqual(dataStoreId, dataStore.Id);
Assert.AreEqual(userId, dataStore.UserId);