Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: clear metadata per url #892

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/Simple.OData.Client.Core/ISession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public interface ISession : IDisposable
/// </summary>
/// <returns>An <see cref="HttpClient"/> instance.</returns>
HttpConnection GetHttpConnection();

/// <summary>
/// Clears base url metadata cache
/// </summary>
void ClearMetadataCache();
}
8 changes: 8 additions & 0 deletions src/Simple.OData.Client.Core/ODataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ public static void ClearMetadataCache()
EdmMetadataCache.Clear();
}

/// <summary>
/// Clears base url metadata cache
/// </summary>
public void ClearBaseUrlMetadataCache()
{
Session.ClearMetadataCache();
}

/// <summary>
/// Returns an instance of a fluent OData client for the specified collection.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Simple.OData.Client.Core/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public void ClearMetadataCache()
{
EdmMetadataCache.Clear(metadataCache.Key);
MetadataCache = null;
_adapter = null;
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/Simple.OData.Client.IntegrationTests/MetadataODataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,23 @@ await Task.WhenAll(

Assert.Equal(1, metadataCallsCount);
}

[Fact]
public async Task MetadataClear()
{
ODataClient.ClearMetadataCache();
var metadataCallsCount = 0;
var settings = new ODataClientSettings
{
BaseUri = _serviceUri,
BeforeRequest = _ => metadataCallsCount++
};
var client = new ODataClient(settings);

await client.GetMetadataAsStringAsync();
client.ClearBaseUrlMetadataCache();
await client.GetMetadataAsStringAsync();

Assert.Equal(2, metadataCallsCount);
}
}