CacheControlHeaderParser Class
Parses the <see cref="CacheControlHeaderValue" /> header.
Namespace:
Assembly:
System.Net.Http.dll
Syntax
public static class CacheControlHeaderParser
Methods
public static System.Net.Http.Headers.CacheControlHeaderValue Parse(string value)
public static System.Net.Http.Headers.CacheControlHeaderValue Parse(string value)
Parameters
- value : stringThe string to parse.
Returns
A System.Net.Http.Headers.CacheControlHeaderValue object.
Remarks
This method is intended for use by the framework and should not be called directly by your code.
Exceptions
- ArgumentNullException : value is null.
- FormatException : value is not a valid Cache-Control header.
public static bool TryParse(string value, out System.Net.Http.Headers.CacheControlHeaderValue& parsedValue)
public static bool TryParse(string value, out System.Net.Http.Headers.CacheControlHeaderValue& parsedValue)
Parameters
- value : stringThe string to parse.
- parsedValue : out System.Net.Http.Headers.CacheControlHeaderValueThe parsed CacheControlHeaderValue object.
Returns
True if the string was parsed successfully; otherwise, false.
Remarks
This method is intended for use by the framework and should not be called directly by your code.
Example Usage
C#
using System.Net.Http.Headers;
// ...
string cacheControlHeaderString = "max-age=3600, public";
CacheControlHeaderValue cacheControl;
if (CacheControlHeaderParser.TryParse(cacheControlHeaderString, out cacheControl))
{
Console.WriteLine($"Max-age: {cacheControl.MaxAge}");
Console.WriteLine($"Public: {cacheControl.Public}");
// ... access other directives
}
else
{
Console.WriteLine("Failed to parse Cache-Control header.");
}
// Using Parse (will throw if invalid)
try
{
CacheControlHeaderValue parsedCacheControl = CacheControlHeaderParser.Parse("no-cache");
Console.WriteLine($"Parsed no-cache: {parsedCacheControl.NoCache}");
}
catch (FormatException ex)
{
Console.WriteLine($"Error parsing: {ex.Message}");
}