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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageTags>UWP Toolkit Windows Controls MSAL Microsoft Graph AadLogin ProfileCard Person PeoplePicker Login</PackageTags>
<SignAssembly>false</SignAssembly>
<GenerateLibraryLayout>true</GenerateLibraryLayout>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<Configurations>Debug;Release;CI</Configurations>
<Platforms>AnyCPU;ARM;ARM64;x64;x86</Platforms>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class BaseRoamingSettingsDataStore : IRoamingSettingsDataStore
public string UserId { get; }

/// <inheritdoc />
public IDictionary<string, object> Cache { get; private set; }
public IDictionary<string, object> Cache { get; private set; } = new Dictionary<string, object>();

/// <summary>
/// Gets an object serializer for converting objects in the data store.
Expand All @@ -53,8 +53,6 @@ public BaseRoamingSettingsDataStore(string userId, string dataStoreId, IObjectSe
Id = dataStoreId;
UserId = userId;
Serializer = objectSerializer;

Cache = null;
}

/// <summary>
Expand All @@ -76,7 +74,7 @@ public BaseRoamingSettingsDataStore(string userId, string dataStoreId, IObjectSe
/// <returns>True if a value exists.</returns>
public bool KeyExists(string key)
{
return Cache != null && Cache.ContainsKey(key);
return Cache?.ContainsKey(key) ?? false;
}

/// <summary>
Expand Down Expand Up @@ -150,8 +148,6 @@ public T Read<T>(string compositeKey, string key, T @default = default)
/// <typeparam name="T">Type of object saved.</typeparam>
public void Save<T>(string key, T value)
{
InitCache();

// Update the cache
Cache[key] = SerializeValue(value);

Expand All @@ -174,8 +170,6 @@ public void Save<T>(string key, T value)
/// <typeparam name="T">Type of object saved.</typeparam>
public void Save<T>(string compositeKey, IDictionary<string, T> values)
{
InitCache();

var type = typeof(T);
var typeInfo = type.GetTypeInfo();

Expand Down Expand Up @@ -255,23 +249,12 @@ public void Save<T>(string compositeKey, IDictionary<string, T> values)
/// <inheritdoc />
public abstract Task Sync();

/// <summary>
/// Initialize the internal cache.
/// </summary>
protected void InitCache()
{
if (Cache == null)
{
Cache = new Dictionary<string, object>();
}
}

/// <summary>
/// Delete the internal cache.
/// </summary>
protected void DeleteCache()
{
Cache = null;
Cache.Clear();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,14 @@ public OneDriveDataStore(string userId, string syncDataFileName, IObjectSerializ
/// <inheritdoc />
public override Task Create()
{
InitCache();

return Task.CompletedTask;
}

/// <inheritdoc />
public override async Task Delete()
{
// Clear the cache
DeleteCache();
Cache.Clear();

// Delete the remote.
await Delete(UserId, Id);
Expand Down Expand Up @@ -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())
{
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ public UserExtensionDataStore(string userId, string extensionId, IObjectSerializ
/// <returns>The newly created Extension object.</returns>
public override async Task Create()
{
InitCache();

await Create(UserId, Id);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down