Skip to content

Commit

Permalink
Dev prepareoss (#3)
Browse files Browse the repository at this point in the history
* day 1 checkin

* save my work 3/30

* refactoring code and adding tests are done

* clean up build scripts

* add docs and format code

* update cla
  • Loading branch information
Jinhuafei authored and HongGit committed Apr 5, 2018
1 parent 6ad9a92 commit e4a7ddb
Show file tree
Hide file tree
Showing 66 changed files with 2,859 additions and 1,216 deletions.
50 changes: 50 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# How to contribute

One of the easiest ways to contribute is to participate in discussions and discuss issues. You can also contribute by submitting pull requests with code changes.


## General feedback and discussions?
Please start a discussion on the [Issue tracker](https://github.com/aspnet/aspnetoutputcache/issues).


## Bugs and feature requests?
For non-security related bugs please log a new issue according to the [Functional bug template](https://github.com/aspnet/AspNetOutputCache/wiki/Functional-bug-template).



## Reporting security issues and bugs
Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) [email protected]. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the [Security TechCenter](https://technet.microsoft.com/en-us/security/ff852094.aspx).


## Contributing code and content

**Obtaining the source code**

If you are an outside contributer, please fork the repository. See the GitHub documentation for [forking a repo](https://help.github.com/articles/fork-a-repo/) if you have any questions about this.

**Submitting a pull request**

You will need to sign a [Contributor License Agreement](https://cla.opensource.microsoft.com//) when submitting your pull request. To complete the Contributor License Agreement (CLA), you will need to follow the instructions provided by the CLA bot when you send the pull request. This needs to only be done once for any Microsoft OSS project.

If you don't know what a pull request is read this article: https://help.github.com/articles/using-pull-requests. Make sure the respository can build and all tests pass.

**Commit/Pull Request Format**

```
Summary of the changes (Less than 80 chars)
- Detail 1
- Detail 2
Addresses #bugnumber (in this specific format)
```

**Tests**

- Tests need to be provided for every bug/feature that is completed.
- Tests only need to be present for issues that need to be verified by QA (e.g. not tasks)
- If there is a scenario that is far too hard to test there does not need to be a test for it.
- "Too hard" is determined by the team as a whole.

**Feedback**

Your pull request will now go through extensive checks by the subject matter experts on our team. Please be patient; we have hundreds of pull requests across all of our repositories. Update your pull request according to feedback until it is approved by one of the ASP.NET team members. After that, one of our team members will add the pull request to **dev**.
21 changes: 21 additions & 0 deletions License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) Microsoft Corporation
All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the ""Software""), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 changes: 27 additions & 8 deletions Microsoft.AspNet.OutputCache.sln
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2036
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.OutputCache.OutputCacheModuleAsync", "src\OutputCacheModuleAsync\Microsoft.AspNet.OutputCache.OutputCacheModuleAsync.csproj", "{3B446E33-7B1C-4A32-AEB8-92DC6CE94F77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.OutputCache.CustomOutputCacheProvider", "test\CustomOutputCacheProvider\Microsoft.AspNet.OutputCache.CustomOutputCacheProvider.csproj", "{A8F3E399-BCAF-4F3E-BC16-5CA98A779916}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.OutputCache.SQLAsyncOutputCacheProvider", "src\SQLAsyncOutputCacheProvider\Microsoft.AspNet.OutputCache.SQLAsyncOutputCacheProvider.csproj", "{062FD141-4E51-4943-8C69-385DDE3D2792}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D256C480-BB19-4239-AD53-DF634A794F41}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{BCF9496E-D71E-4F4A-814B-B37830A87FF3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.OutputCache.OutputCacheModuleAsync.Test", "test\Microsoft.AspNet.OutputCache.OutputCacheModuleAsync.Test\Microsoft.AspNet.OutputCache.OutputCacheModuleAsync.Test.csproj", "{89636B89-D392-47CA-9D81-BEB4C5252D75}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.OutputCache.SQLAsyncOutputCacheProvider.Test", "test\Microsoft.AspNet.OutputCache.SQLAsyncOutputCacheProvider.Test\Microsoft.AspNet.OutputCache.SQLAsyncOutputCacheProvider.Test.csproj", "{B2C127BD-077B-4B9A-8163-F77DF76CE6A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -19,16 +25,29 @@ Global
{3B446E33-7B1C-4A32-AEB8-92DC6CE94F77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B446E33-7B1C-4A32-AEB8-92DC6CE94F77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B446E33-7B1C-4A32-AEB8-92DC6CE94F77}.Release|Any CPU.Build.0 = Release|Any CPU
{A8F3E399-BCAF-4F3E-BC16-5CA98A779916}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A8F3E399-BCAF-4F3E-BC16-5CA98A779916}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A8F3E399-BCAF-4F3E-BC16-5CA98A779916}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A8F3E399-BCAF-4F3E-BC16-5CA98A779916}.Release|Any CPU.Build.0 = Release|Any CPU
{062FD141-4E51-4943-8C69-385DDE3D2792}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{062FD141-4E51-4943-8C69-385DDE3D2792}.Debug|Any CPU.Build.0 = Debug|Any CPU
{062FD141-4E51-4943-8C69-385DDE3D2792}.Release|Any CPU.ActiveCfg = Release|Any CPU
{062FD141-4E51-4943-8C69-385DDE3D2792}.Release|Any CPU.Build.0 = Release|Any CPU
{89636B89-D392-47CA-9D81-BEB4C5252D75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{89636B89-D392-47CA-9D81-BEB4C5252D75}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89636B89-D392-47CA-9D81-BEB4C5252D75}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89636B89-D392-47CA-9D81-BEB4C5252D75}.Release|Any CPU.Build.0 = Release|Any CPU
{B2C127BD-077B-4B9A-8163-F77DF76CE6A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B2C127BD-077B-4B9A-8163-F77DF76CE6A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2C127BD-077B-4B9A-8163-F77DF76CE6A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2C127BD-077B-4B9A-8163-F77DF76CE6A8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3B446E33-7B1C-4A32-AEB8-92DC6CE94F77} = {D256C480-BB19-4239-AD53-DF634A794F41}
{062FD141-4E51-4943-8C69-385DDE3D2792} = {D256C480-BB19-4239-AD53-DF634A794F41}
{89636B89-D392-47CA-9D81-BEB4C5252D75} = {BCF9496E-D71E-4F4A-814B-B37830A87FF3}
{B2C127BD-077B-4B9A-8163-F77DF76CE6A8} = {BCF9496E-D71E-4F4A-814B-B37830A87FF3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {51897B01-673A-47FD-87BC-8FD7C01950E6}
EndGlobalSection
EndGlobal
17 changes: 12 additions & 5 deletions MicrosoftAspNetOutputCache.msbuild
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,32 @@
<ItemGroup>
<AssemblyProject Include="src\OutputCacheModuleAsync\Microsoft.AspNet.OutputCache.OutputCacheModuleAsync.csproj" />
<AssemblyProject Include="src\SQLAsyncOutputCacheProvider\Microsoft.AspNet.OutputCache.SQLAsyncOutputCacheProvider.csproj" />
<AssemblyProject Include="test\CustomOutputCacheProvider\Microsoft.AspNet.OutputCache.CustomOutputCacheProvider.csproj" />
</ItemGroup>
<ItemGroup>
<TestProject Include="test\Microsoft.AspNet.OutputCache.SQLAsyncOutputCacheProvider.Test\Microsoft.AspNet.OutputCache.SQLAsyncOutputCacheProvider.Test.csproj" />
<TestProject Include="test\Microsoft.AspNet.OutputCache.OutputCacheModuleAsync.Test\Microsoft.AspNet.OutputCache.OutputCacheModuleAsync.Test.csproj" />
</ItemGroup>
<ItemGroup>
<PackageProject Include="src\Packages\Packages.csproj" />
</ItemGroup>

<Target Name="Build" DependsOnTargets="BuildAssemblies;BuildPackages" />
<Target Name="Build" DependsOnTargets="BuildAssemblies;UnitTest;BuildPackages" />
<Target Name="Clean" DependsOnTargets="CleanPackages;CleanAssemblies" />
<Target Name="Rebuild" DependsOnTargets="Clean;Build" />

<Target Name="BuildAssemblies" DependsOnTargets="RestorePackages">
<MSBuild Targets="Build" Projects="@(AssemblyProject)" />
<MSBuild Targets="Build" Projects="@(AssemblyProject);@(TestProject)" />
</Target>

<Target Name="CleanAssemblies">
<MSBuild Targets="Clean" Projects="Microsoft.Aspnet.OutputCache.sln" />
<MSBuild Targets="Clean" Projects="Microsoft.AspNet.OutputCache.sln" />
</Target>

<Target Name="RebuildAssemblies" DependsOnTargets="Clean;Build" />

<!-- Packages build -->

<Target Name="BuildPackages" DependsOnTargets="RestorePackages">
<Target Name="BuildPackages" DependsOnTargets="RestorePackages">
<MSBuild Targets="" Projects="@(PackageProject)" />
</Target>

Expand All @@ -39,6 +42,10 @@
<Target Name="RestorePackages">
<Exec Command=".nuget\NuGet.exe restore" />
</Target>

<Target Name="UnitTest">
<MSBuild Targets="XunitTest" Projects="@(TestProject)" />
</Target>

<Import Project="tools\MicrosoftAspNetOutputCache.targets"/>
</Project>
28 changes: 28 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Introduction
OutputCacheModule is ASP.NET’s default handler for storing the generated output of pages, controls, and HTTP responses. This content can then be reused when appropriate to improve performance. Prior to the .NET Framework 4.6.2, the OutputCache Module did not support async read/write to the storage. You can find more details on [this blog post](https://blogs.msdn.microsoft.com/webdev/2016/12/05/introducing-the-asp-net-async-outputcache-module/).

## How to build
1. Open a [VS developer command prompt](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs)
2. Run build.cmd. This will build Nuget package and run all the unit tests.
3. All the build artifacts will be under AspNetOutputCache\bin\Release\ folder.

## How to contribute
Information on contributing to this repo is in the [Contributing Guide](CONTRIBUTING.md).

## Settings of the module and providers

#### Microsoft.AspNet.OutputCache.SQLAsyncOutputCacheProvider

The settings of this provider is located in the following configuration section in web.config.
```
<caching>
<outputCache defaultProvider="SQLAsyncOutputCacheProvider">
<providers>
<add name="SQLAsyncOutputCacheProvider" connectionStringName="DefaultConnection" UseInMemoryTable="[true|false]"
type="Microsoft.AspNet.OutputCache.SQLAsyncOutputCacheProvider.SQLAsyncOutputCacheProvider, Microsoft.AspNet.OutputCache.SQLAsyncOutputCacheProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</providers>
</outputCache>
</caching>
```

1. *UseInMemoryTable* - Indicates whether to use Sql server 2016 In-Memory OLTP for the provider.
18 changes: 2 additions & 16 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,9 @@ setlocal

set logOptions=/flp:Summary;Verbosity=diag;LogFile=msbuild.log /flp1:warningsonly;logfile=msbuild.wrn /flp2:errorsonly;logfile=msbuild.err

set MSBUILDEXE=
if exist "%SystemDrive%\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" (
set MSBUILDEXE="%SystemDrive%\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
GOTO BUILD
)

if exist "%SystemDrive%\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" (
set MSBUILDEXE="%SystemDrive%\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe"
GOTO BUILD
)

if not defined MSBUILDEXE (
set MSBUILDEXE="C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
)
echo Please build from VS 2015(or newer version) Developer Command Prompt

:BUILD
REM %MSBUILDEXE% "%~dp0\MicrosoftAspNetOutputCache.msbuild" %logOptions% /v:d /maxcpucount /nodeReuse:false %*
%MSBUILDEXE% "%~dp0\MicrosoftAspNetOutputCache.msbuild" %logOptions% /v:diag /maxcpucount /nodeReuse:false %*
msbuild "%~dp0MicrosoftAspNetOutputCache.msbuild" %logOptions% /v:m /maxcpucount /nodeReuse:false %*

endlocal
6 changes: 4 additions & 2 deletions src/OutputCacheModuleAsync/CacheDirectives.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Microsoft.AspNet.OutputCache {

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See the License.txt file in the project root for full license information.

namespace Microsoft.AspNet.OutputCache {
sealed class CacheDirectives {
public const string NoCache = "no-cache";
public const string NoStore = "no-store";
Expand Down
5 changes: 4 additions & 1 deletion src/OutputCacheModuleAsync/CachedRawResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Microsoft.AspNet.OutputCache {
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See the License.txt file in the project root for full license information.

namespace Microsoft.AspNet.OutputCache {
using System;

[Serializable]
Expand Down
5 changes: 4 additions & 1 deletion src/OutputCacheModuleAsync/CachedVary.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Microsoft.AspNet.OutputCache {
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See the License.txt file in the project root for full license information.

namespace Microsoft.AspNet.OutputCache {
using System;

[Serializable]
Expand Down
20 changes: 10 additions & 10 deletions src/OutputCacheModuleAsync/Converter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Microsoft.AspNet.OutputCache {
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See the License.txt file in the project root for full license information.

namespace Microsoft.AspNet.OutputCache {
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -49,7 +52,7 @@ public Converter() {
IHttpResponseElement_GetSize = IHttpResponseElementType.GetMethod("GetSize");

// Fileds
HttpFileResponseElement_FileName = HttpFileResponseElementType.GetField("_filename", BindingFlags.Instance);
HttpFileResponseElement_FileName = HttpFileResponseElementType.GetField("_filename", bindingFlags);
HttpFileResponseElement_Offset = HttpFileResponseElementType.GetField("_offset", bindingFlags);
HttpFileResponseElement_IsImpersonating = HttpFileResponseElementType.GetField("_isImpersonating", bindingFlags);
HttpFileResponseElement_UseTransmitFile = HttpFileResponseElementType.GetField("_useTransmitFile", bindingFlags);
Expand Down Expand Up @@ -102,11 +105,11 @@ public CachedRawResponse CreateCachedRawResponse(OutputCacheEntry oce) {
foreach (var re in oce.ResponseBuffers) {
// convert the public ResponseElement classes back to IHttpResponseElement internal classes
object elem = null;
if (re is FileResponseElement) {
elem = CreateHttpFileResponseElement((MemoryResponseElement)re);
if (re is OutputCacheFileResponseElement) {
elem = CreateHttpFileResponseElement((OutputCacheFileResponseElement)re);
}
else if (re is SubstitutionResponseElement) {
elem = CreateHttpSubstBlockResponseElement((MemoryResponseElement)re);
elem = CreateHttpSubstBlockResponseElement((SubstitutionResponseElement)re);
}
else if (re is MemoryResponseElement) {
elem = CreateHttpResponseBufferElement((MemoryResponseElement)re);
Expand Down Expand Up @@ -146,9 +149,7 @@ private ResponseElement CreateMemoryResponseElement(object o) {
return new MemoryResponseElement(b, length);
}

private object CreateHttpFileResponseElement(ResponseElement e) {
var fre = (OutputCacheFileResponseElement)e;

private object CreateHttpFileResponseElement(OutputCacheFileResponseElement fre) {
//[Lan] how about we extend FileResponseElement class to store those two bool value
// HttpContext context = HttpContext.Current;
// HttpWorkerRequest wr = (context != null) ? context.WorkerRequest : null;
Expand All @@ -162,8 +163,7 @@ private object CreateHttpFileResponseElement(ResponseElement e) {
return HttpFileResponseElement_Ctor.Invoke(new object[] { fre.Path, fre.Offset, fre.Length, fre.IsImpersonating, fre.SupportsLongTransmitFile });
}

private object CreateHttpSubstBlockResponseElement(ResponseElement e) {
var sre = (SubstitutionResponseElement)e;
private object CreateHttpSubstBlockResponseElement(SubstitutionResponseElement sre) {
return HttpSubstBlockResponseElement_Ctor.Invoke(new object[] { sre.Callback });
}

Expand Down
6 changes: 4 additions & 2 deletions src/OutputCacheModuleAsync/DependencyCacheEntry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace Microsoft.AspNet.OutputCache {
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See the License.txt file in the project root for full license information.

namespace Microsoft.AspNet.OutputCache {
using System;
using System.Web.Caching;

[Serializable]
sealed class DependencyCacheEntry {
Expand Down
5 changes: 4 additions & 1 deletion src/OutputCacheModuleAsync/HttpCachePolicySettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Microsoft.AspNet.OutputCache {
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See the License.txt file in the project root for full license information.

namespace Microsoft.AspNet.OutputCache {
using System;
using System.Collections.Generic;
using System.Web;
Expand Down
5 changes: 4 additions & 1 deletion src/OutputCacheModuleAsync/HttpHeaders.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Microsoft.AspNet.OutputCache {
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See the License.txt file in the project root for full license information.

namespace Microsoft.AspNet.OutputCache {
sealed class HttpHeaders {
public const string IfModifiedSince = "If-Modified-Since";
public const string IfNoneMatch = "If-None-Match";
Expand Down
5 changes: 4 additions & 1 deletion src/OutputCacheModuleAsync/HttpMethods.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Microsoft.AspNet.OutputCache {
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See the License.txt file in the project root for full license information.

namespace Microsoft.AspNet.OutputCache {
sealed class HttpMethods {
public const string POST = "POST";
public const string HEAD = "HEAD";
Expand Down
5 changes: 4 additions & 1 deletion src/OutputCacheModuleAsync/HttpRawResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Microsoft.AspNet.OutputCache {
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See the License.txt file in the project root for full license information.

namespace Microsoft.AspNet.OutputCache {
using System;
using System.Collections;
using System.Collections.Specialized;
Expand Down
5 changes: 4 additions & 1 deletion src/OutputCacheModuleAsync/ICacheDependencyHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Microsoft.AspNet.OutputCache {
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See the License.txt file in the project root for full license information.

namespace Microsoft.AspNet.OutputCache {
using System.Runtime.Caching;
using System.Threading.Tasks;

Expand Down
Loading

0 comments on commit e4a7ddb

Please sign in to comment.