Skip to content

Commit

Permalink
Merge branch 'release/2.1' into release/2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate McMaster committed Nov 7, 2018
3 parents 653ace5 + 290f4b3 + a3662be commit 99b874c
Show file tree
Hide file tree
Showing 116 changed files with 13,973 additions and 15 deletions.
273 changes: 259 additions & 14 deletions Extensions.sln

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions eng/Baseline.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
<!-- Auto generated. Do not edit manually, use eng/tools/BaselineGenerator/ to recreate. -->
<Project>
<!-- Package: Microsoft.Extensions.Caching.Abstractions-->
<PropertyGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.Caching.Abstractions' ">
<BaselinePackageVersion>2.1.2</BaselinePackageVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.Caching.Abstractions' AND '$(TargetFramework)' == 'netstandard2.0' ">
<BaselinePackageReference Include="Microsoft.Extensions.Primitives" Version="[2.1.1, )" />
</ItemGroup>
<!-- Package: Microsoft.Extensions.Caching.Memory-->
<PropertyGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.Caching.Memory' ">
<BaselinePackageVersion>2.1.2</BaselinePackageVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.Caching.Memory' AND '$(TargetFramework)' == 'netstandard2.0' ">
<BaselinePackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="[2.1.2, )" />
<BaselinePackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="[2.1.1, )" />
<BaselinePackageReference Include="Microsoft.Extensions.Options" Version="[2.1.1, )" />
</ItemGroup>
<!-- Package: Microsoft.Extensions.Caching.Redis-->
<PropertyGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.Caching.Redis' ">
<BaselinePackageVersion>2.1.2</BaselinePackageVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.Caching.Redis' AND '$(TargetFramework)' == 'netstandard2.0' ">
<BaselinePackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="[2.1.2, )" />
<BaselinePackageReference Include="Microsoft.Extensions.Options" Version="[2.1.1, )" />
<BaselinePackageReference Include="StackExchange.Redis.StrongName" Version="[1.2.6, )" />
</ItemGroup>
<!-- Package: Microsoft.Extensions.Caching.SqlServer-->
<PropertyGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.Caching.SqlServer' ">
<BaselinePackageVersion>2.1.2</BaselinePackageVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.Caching.SqlServer' AND '$(TargetFramework)' == 'netstandard2.0' ">
<BaselinePackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="[2.1.2, )" />
<BaselinePackageReference Include="Microsoft.Extensions.Options" Version="[2.1.1, )" />
<BaselinePackageReference Include="System.Data.SqlClient" Version="[4.5.1, )" />
</ItemGroup>
<!-- Package: Microsoft.Extensions.Configuration.Abstractions-->
<PropertyGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.Configuration.Abstractions' ">
<BaselinePackageVersion>2.1.1</BaselinePackageVersion>
Expand Down
6 changes: 5 additions & 1 deletion eng/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<PropertyGroup Label="Package Versions: Auto">
<FSharpCorePackageVersion>4.2.1</FSharpCorePackageVersion>
<InternalAspNetCoreSdkPackageVersion>2.2.0-preview2-20181105.3</InternalAspNetCoreSdkPackageVersion>
<MicrosoftNETCoreAppPackageVersion>2.2.0-rtm-27029-02</MicrosoftNETCoreAppPackageVersion>
<MicrosoftNETCoreAppPackageVersion>2.2.0-rtm-27105-02</MicrosoftNETCoreAppPackageVersion>
<MicrosoftWin32RegistryPackageVersion>4.5.0</MicrosoftWin32RegistryPackageVersion>
<NETStandardLibrary20PackageVersion>2.0.3</NETStandardLibrary20PackageVersion>
<SystemComponentModelAnnotationsPackageVersion>4.5.0</SystemComponentModelAnnotationsPackageVersion>
<SystemDataSqlClientPackageVersion>4.6.0-rtm-27105-02</SystemDataSqlClientPackageVersion>
<SystemDiagnosticsDiagnosticSourcePackageVersion>4.5.0</SystemDiagnosticsDiagnosticSourcePackageVersion>
<SystemDiagnosticsEventLogPackageVersion>4.5.0</SystemDiagnosticsEventLogPackageVersion>
<SystemIOPipelinesPackageVersion>4.5.2</SystemIOPipelinesPackageVersion>
Expand All @@ -32,6 +33,7 @@
<LatestPackageReference Include="FSharp.Core" Version="$(FSharpCorePackageVersion)" />
<LatestPackageReference Include="Microsoft.Win32.Registry" Version="$(MicrosoftWin32RegistryPackageVersion)" />
<LatestPackageReference Include="System.ComponentModel.Annotations" Version="$(SystemComponentModelAnnotationsPackageVersion)" />
<LatestPackageReference Include="System.Data.SqlClient" Version="$(SystemDataSqlClientPackageVersion)" />
<LatestPackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsDiagnosticSourcePackageVersion)" />
<LatestPackageReference Include="System.Diagnostics.EventLog" Version="$(SystemDiagnosticsEventLogPackageVersion)" />
<LatestPackageReference Include="System.IO.Pipelines" Version="$(SystemIOPipelinesPackageVersion)" />
Expand Down Expand Up @@ -64,6 +66,8 @@
<LatestPackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<LatestPackageReference Include="Serilog.Extensions.Logging" Version="1.4.0" />
<LatestPackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
<LatestPackageReference Include="StackExchange.Redis.StrongName" Version="1.2.6" />
<LatestPackageReference Include="StackExchange.Redis" Version="2.0.513" />
<LatestPackageReference Include="xunit.abstractions" Version="2.0.1" />
<LatestPackageReference Include="xunit.analyzers" Version="0.10.0" />
<LatestPackageReference Include="xunit.assert" Version="2.3.1" />
Expand Down
5 changes: 5 additions & 0 deletions eng/ProjectReferences.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<!-- This file is automatically generated. Run `build.cmd /t:GenerateProjectList` to update. -->
<Project>
<ItemGroup>
<ProjectReferenceProvider Include="Microsoft.Extensions.Caching.Abstractions" ProjectPath="$(RepositoryRoot)src/Caching/Abstractions/src/Microsoft.Extensions.Caching.Abstractions.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Caching.Memory" ProjectPath="$(RepositoryRoot)src/Caching/Memory/src/Microsoft.Extensions.Caching.Memory.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Caching.Redis" ProjectPath="$(RepositoryRoot)src/Caching/Redis/src/Microsoft.Extensions.Caching.Redis.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Caching.SqlServer" ProjectPath="$(RepositoryRoot)src/Caching/SqlServer/src/Microsoft.Extensions.Caching.SqlServer.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Caching.StackExchangeRedis" ProjectPath="$(RepositoryRoot)src/Caching/StackExchangeRedis/src/Microsoft.Extensions.Caching.StackExchangeRedis.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Configuration.Abstractions" ProjectPath="$(RepositoryRoot)src/Configuration/Config.Abstractions/src/Microsoft.Extensions.Configuration.Abstractions.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Configuration.AzureKeyVault" ProjectPath="$(RepositoryRoot)src/Configuration/Config.AzureKeyVault/src/Microsoft.Extensions.Configuration.AzureKeyVault.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Configuration.Binder" ProjectPath="$(RepositoryRoot)src/Configuration/Config.Binder/src/Microsoft.Extensions.Configuration.Binder.csproj" />
Expand Down
4 changes: 4 additions & 0 deletions eng/tools/BaselineGenerator/baseline.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<Baseline>
<Package Id="Microsoft.Extensions.Caching.Abstractions" Version="2.1.2" />
<Package Id="Microsoft.Extensions.Caching.Memory" Version="2.1.2" />
<Package Id="Microsoft.Extensions.Caching.Redis" Version="2.1.2" />
<Package Id="Microsoft.Extensions.Caching.SqlServer" Version="2.1.2" />
<Package Id="Microsoft.Extensions.Configuration.Abstractions" Version="2.1.1" />
<Package Id="Microsoft.Extensions.Configuration.AzureKeyVault" Version="2.1.1" />
<Package Id="Microsoft.Extensions.Configuration.Binder" Version="2.1.1" />
Expand Down
7 changes: 7 additions & 0 deletions src/Caching/Abstractions/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.props))\Directory.Build.props" />

<PropertyGroup>
<IsProductComponent>true</IsProductComponent>
</PropertyGroup>
</Project>
185 changes: 185 additions & 0 deletions src/Caching/Abstractions/src/CacheEntryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.Extensions.Primitives;

namespace Microsoft.Extensions.Caching.Memory
{
public static class CacheEntryExtensions
{
/// <summary>
/// Sets the priority for keeping the cache entry in the cache during a memory pressure tokened cleanup.
/// </summary>
/// <param name="entry"></param>
/// <param name="priority"></param>
public static ICacheEntry SetPriority(
this ICacheEntry entry,
CacheItemPriority priority)
{
entry.Priority = priority;
return entry;
}

/// <summary>
/// Expire the cache entry if the given <see cref="IChangeToken"/> expires.
/// </summary>
/// <param name="entry">The <see cref="ICacheEntry"/>.</param>
/// <param name="expirationToken">The <see cref="IChangeToken"/> that causes the cache entry to expire.</param>
public static ICacheEntry AddExpirationToken(
this ICacheEntry entry,
IChangeToken expirationToken)
{
if (expirationToken == null)
{
throw new ArgumentNullException(nameof(expirationToken));
}

entry.ExpirationTokens.Add(expirationToken);
return entry;
}

/// <summary>
/// Sets an absolute expiration time, relative to now.
/// </summary>
/// <param name="entry"></param>
/// <param name="relative"></param>
public static ICacheEntry SetAbsoluteExpiration(
this ICacheEntry entry,
TimeSpan relative)
{
entry.AbsoluteExpirationRelativeToNow = relative;
return entry;
}

/// <summary>
/// Sets an absolute expiration date for the cache entry.
/// </summary>
/// <param name="entry"></param>
/// <param name="absolute"></param>
public static ICacheEntry SetAbsoluteExpiration(
this ICacheEntry entry,
DateTimeOffset absolute)
{
entry.AbsoluteExpiration = absolute;
return entry;
}

/// <summary>
/// Sets how long the cache entry can be inactive (e.g. not accessed) before it will be removed.
/// This will not extend the entry lifetime beyond the absolute expiration (if set).
/// </summary>
/// <param name="entry"></param>
/// <param name="offset"></param>
public static ICacheEntry SetSlidingExpiration(
this ICacheEntry entry,
TimeSpan offset)
{
entry.SlidingExpiration = offset;
return entry;
}

/// <summary>
/// The given callback will be fired after the cache entry is evicted from the cache.
/// </summary>
/// <param name="entry"></param>
/// <param name="callback"></param>
public static ICacheEntry RegisterPostEvictionCallback(
this ICacheEntry entry,
PostEvictionDelegate callback)
{
if (callback == null)
{
throw new ArgumentNullException(nameof(callback));
}

return entry.RegisterPostEvictionCallback(callback, state: null);
}

/// <summary>
/// The given callback will be fired after the cache entry is evicted from the cache.
/// </summary>
/// <param name="entry"></param>
/// <param name="callback"></param>
/// <param name="state"></param>
public static ICacheEntry RegisterPostEvictionCallback(
this ICacheEntry entry,
PostEvictionDelegate callback,
object state)
{
if (callback == null)
{
throw new ArgumentNullException(nameof(callback));
}

entry.PostEvictionCallbacks.Add(new PostEvictionCallbackRegistration()
{
EvictionCallback = callback,
State = state
});
return entry;
}

/// <summary>
/// Sets the value of the cache entry.
/// </summary>
/// <param name="entry"></param>
/// <param name="value"></param>
public static ICacheEntry SetValue(
this ICacheEntry entry,
object value)
{
entry.Value = value;
return entry;
}

/// <summary>
/// Sets the size of the cache entry value.
/// </summary>
/// <param name="entry"></param>
/// <param name="size"></param>
public static ICacheEntry SetSize(
this ICacheEntry entry,
long size)
{
if (size < 0)
{
throw new ArgumentOutOfRangeException(nameof(size), size, $"{nameof(size)} must be non-negative.");
}

entry.Size = size;
return entry;
}

/// <summary>
/// Applies the values of an existing <see cref="MemoryCacheEntryOptions"/> to the entry.
/// </summary>
/// <param name="entry"></param>
/// <param name="options"></param>
public static ICacheEntry SetOptions(this ICacheEntry entry, MemoryCacheEntryOptions options)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}

entry.AbsoluteExpiration = options.AbsoluteExpiration;
entry.AbsoluteExpirationRelativeToNow = options.AbsoluteExpirationRelativeToNow;
entry.SlidingExpiration = options.SlidingExpiration;
entry.Priority = options.Priority;
entry.Size = options.Size;

foreach (var expirationToken in options.ExpirationTokens)
{
entry.AddExpirationToken(expirationToken);
}

foreach (var postEvictionCallback in options.PostEvictionCallbacks)
{
entry.RegisterPostEvictionCallback(postEvictionCallback.EvictionCallback, postEvictionCallback.State);
}

return entry;
}
}
}
17 changes: 17 additions & 0 deletions src/Caching/Abstractions/src/CacheItemPriority.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.Extensions.Caching.Memory
{
// TODO: Granularity?
/// <summary>
/// Specifies how items are prioritized for preservation during a memory pressure triggered cleanup.
/// </summary>
public enum CacheItemPriority
{
Low,
Normal,
High,
NeverRemove,
}
}
50 changes: 50 additions & 0 deletions src/Caching/Abstractions/src/DistributedCacheEntryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;

namespace Microsoft.Extensions.Caching.Distributed
{
public static class DistributedCacheEntryExtensions
{
/// <summary>
/// Sets an absolute expiration time, relative to now.
/// </summary>
/// <param name="options"></param>
/// <param name="relative"></param>
public static DistributedCacheEntryOptions SetAbsoluteExpiration(
this DistributedCacheEntryOptions options,
TimeSpan relative)
{
options.AbsoluteExpirationRelativeToNow = relative;
return options;
}

/// <summary>
/// Sets an absolute expiration date for the cache entry.
/// </summary>
/// <param name="options"></param>
/// <param name="absolute"></param>
public static DistributedCacheEntryOptions SetAbsoluteExpiration(
this DistributedCacheEntryOptions options,
DateTimeOffset absolute)
{
options.AbsoluteExpiration = absolute;
return options;
}

/// <summary>
/// Sets how long the cache entry can be inactive (e.g. not accessed) before it will be removed.
/// This will not extend the entry lifetime beyond the absolute expiration (if set).
/// </summary>
/// <param name="options"></param>
/// <param name="offset"></param>
public static DistributedCacheEntryOptions SetSlidingExpiration(
this DistributedCacheEntryOptions options,
TimeSpan offset)
{
options.SlidingExpiration = offset;
return options;
}
}
}
Loading

0 comments on commit 99b874c

Please sign in to comment.