Skip to content

Commit 731ac90

Browse files
committed
adding resource strings
adding resource strings
1 parent 4de8975 commit 731ac90

7 files changed

Lines changed: 553 additions & 57 deletions

src/OutputCacheModuleAsync/InMemoryOutputCacheProvider.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
using System.Runtime.Caching;
44
using System.Threading.Tasks;
55
using System.Web.Caching;
6-
6+
using Microsoft.AspNet.OutputCache.Resource;
77
internal class InMemoryOutputCacheProvider : OutputCacheProviderAsync {
8-
private readonly MemoryCache _cache = new MemoryCache("Microsoft.AspNet.OutputCache Default In-Memory Provider");
8+
private readonly MemoryCache _cache = new MemoryCache(SR.Microsoft_AspNet_OutputCache_Default_InMemory_Provider);
99

1010
public override Task<object> GetAsync(string key) {
11-
return Task.FromResult(Get(key)); //.Run(() => Get(key));
11+
return Task.FromResult(Get(key));
1212
}
1313

1414
public override Task<object> AddAsync(string key, object entry, DateTime utcExpiry) {
15-
return Task.FromResult(Add(key,entry,utcExpiry));//.Run(() => Add(key, entry, utcExpiry));
15+
return Task.FromResult(Add(key,entry,utcExpiry));
1616
}
1717

1818
public override Task SetAsync(string key, object entry, DateTime utcExpiry) {
19-
return Task.Run(() => Set(key, entry, utcExpiry));
19+
Set(key, entry, utcExpiry);
20+
return Task.CompletedTask;
2021
}
2122

22-
public override Task RemoveAsync(string key) {
23-
return Task.Run(() => Remove(key));
23+
public override Task RemoveAsync(string key) {
24+
Remove(key);
25+
return Task.CompletedTask;
2426
}
2527

2628
public override object Get(string key) {

src/OutputCacheModuleAsync/Microsoft.AspNet.OutputCache.OutputCacheModuleAsync.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,21 @@
5252
<Compile Include="OutputCacheHelper.cs" />
5353
<Compile Include="OutputCacheModuleAsync.cs" />
5454
<Compile Include="Properties\AssemblyInfo.cs" />
55+
<Compile Include="Resource\SR.Designer.cs">
56+
<AutoGen>True</AutoGen>
57+
<DesignTime>True</DesignTime>
58+
<DependentUpon>SR.resx</DependentUpon>
59+
</Compile>
5560
<Compile Include="TaskAsyncHelper.cs" />
5661
<Compile Include="TaskWrapperAsyncResults.cs" />
5762
<Compile Include="Util.cs" />
5863
</ItemGroup>
59-
<ItemGroup />
64+
<ItemGroup>
65+
<EmbeddedResource Include="Resource\SR.resx">
66+
<Generator>ResXFileCodeGenerator</Generator>
67+
<LastGenOutput>SR.Designer.cs</LastGenOutput>
68+
</EmbeddedResource>
69+
</ItemGroup>
6070
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6171
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
6272
Other similar extension points exist, see Microsoft.Common.targets.

src/OutputCacheModuleAsync/OutputCacheHelper.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.IO;
2+
using Microsoft.AspNet.OutputCache.Resource;
23

34
namespace Microsoft.AspNet.OutputCache {
45
using System.Collections.Generic;
@@ -204,7 +205,7 @@ public async Task InsertResponse(string cachedVaryKey,
204205
&& slidingExpiration == Cache.NoSlidingExpiration
205206
&& (dependencies == null || dependencies.GetFileDependencies() != null));
206207
if (!canUseProvider) {
207-
throw new Exception("Provider_does_not_support_policy_for_responses");
208+
throw new Exception(SR.Provider_does_not_support_policy_for_responses);
208209
}
209210
if (cachedVary != null) {
210211
/*
@@ -280,7 +281,7 @@ public static bool ContainsNonShareableCookies(HttpResponse response) {
280281

281282
public static void UseSnapshot(HttpRawResponse rawResponse, bool sendBody, HttpResponse response) {
282283
if (response.HeadersWritten)
283-
throw new HttpException("Cannot_use_snapshot_after_headers_sent");
284+
throw new HttpException(SR.Cannot_use_snapshot_after_headers_sent);
284285
response.Clear();
285286
response.ClearHeaders();
286287
// restore status
@@ -299,7 +300,7 @@ public static HttpRawResponse GetSnapshot(HttpResponse response) {
299300
var headers = new NameValueCollection();
300301
const bool hasSubstBlocks = false;
301302
if (response.HeadersWritten)
302-
throw new HttpException("Cannot_get_snapshot_if_not_buffered");
303+
throw new HttpException(SR.Cannot_get_snapshot_if_not_buffered);
303304
// data
304305
ArrayList buffers = OutputCacheUtility.GetContentBuffers(response);
305306
// headers (after data as the data has side effects (like charset, see ASURT 113202))

src/OutputCacheModuleAsync/OutputCacheModuleAsync.cs

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Microsoft.AspNet.OutputCache {
1+
using System.Text;
2+
3+
namespace Microsoft.AspNet.OutputCache {
24
using System.Collections.Generic;
35
using System;
46
using System.Linq;
@@ -10,7 +12,7 @@
1012
using System.Web.Configuration;
1113
using System.Diagnostics;
1214
using System.Configuration;
13-
15+
using Resource;
1416
/// <summary>
1517
/// OutputCache Async Module, this Module is able to use Async type of OutputCache Providers
1618
/// </summary>
@@ -62,7 +64,7 @@ private async Task OnEnterAsync(object source, EventArgs eventArgs) {
6264
}
6365

6466
// Create a lookup key. Also store the key in global parameter _key to be used inside OnLeave() later
65-
string key = _key = await OutputCacheHelper.CreateOutputCachedItemKeyAsync(context, null);
67+
string key = _key = OutputCacheHelper.CreateOutputCachedItemKeyAsync(context, null);
6668

6769
// Lookup the cache vary using the key
6870
object item = await _outputCacheHelper.Get(key);
@@ -178,7 +180,7 @@ private async Task CacheResponse(HttpContext context, HttpResponse response) {
178180
string[] varyByParams = settings.IgnoreParams ? null : settings.VaryByParams;
179181
/* Create the key if it was not created in OnEnter */
180182
if (_key == null) {
181-
_key = await OutputCacheHelper.CreateOutputCachedItemKeyAsync(context, null);
183+
_key = OutputCacheHelper.CreateOutputCachedItemKeyAsync(context, null);
182184
Debug.Assert(_key != null, "_key != null");
183185
}
184186
if (settings.VaryByContentEncodings == null && varyByHeaders == null && varyByParams == null &&
@@ -221,16 +223,16 @@ private async Task CacheResponse(HttpContext context, HttpResponse response) {
221223
VaryByAllParams = varyByAllParams,
222224
VaryByCustom = settings.VaryByCustom
223225
};
224-
keyRawResponse = await OutputCacheHelper.CreateOutputCachedItemKeyAsync(context, cachedVary);
226+
keyRawResponse = OutputCacheHelper.CreateOutputCachedItemKeyAsync(context, cachedVary);
225227
if (keyRawResponse == null) {
226-
Debug.WriteLine("OutputCacheModuleLeave", "Couldn't add non-cacheable post.\n\tkey=" + _key);
228+
Debug.WriteLine(SR.OutputCacheModuleLeave, string.Format(SR.Couldnot_add_non_cacheable_post,_key));
227229
return;
228230
}
229231
// it is possible that the user code calculating custom vary-by
230232
// string would Flush making the response non-cacheable. Check fo it here.
231233
if (response.HeadersWritten) {
232-
Debug.WriteLine("OutputCacheModuleLeave",
233-
"Response.Flush() inside GetVaryByCustomstring\n\tkey=" + _key);
234+
Debug.WriteLine(SR.OutputCacheModuleLeave,
235+
string.Format(SR.Response_Flush_inside_GetVaryByCustomstring, _key));
234236
return;
235237
}
236238
}
@@ -260,7 +262,7 @@ private async Task CacheResponse(HttpContext context, HttpResponse response) {
260262
KernelCacheUrl = kernelCacheUrl,
261263
CachedVaryId = cachedVaryId
262264
};
263-
Debug.WriteLine("OutputCacheModuleLeave", "Adding response to cache. Key=" + keyRawResponse);
265+
Debug.WriteLine(SR.OutputCacheModuleLeave, string.Format(SR.Adding_response_to_cache, keyRawResponse));
264266
CacheDependency dep = OutputCacheUtility.CreateCacheDependency(context.Response);
265267
try {
266268
await _outputCacheHelper.InsertResponse(_key, cachedVary,
@@ -303,8 +305,8 @@ private static void GetCachedResponse(HttpContext context, HttpRequest request,
303305
}
304306
}
305307
catch {
306-
Debug.WriteLine("OutputCacheModuleEnter",
307-
"Ignore If-Modified-Since header, invalid format: " + ifModifiedSinceHeader);
308+
Debug.WriteLine(SR.OutputCacheModuleEnter,
309+
string.Format(SR.Ignore_IfModifiedSince_header, ifModifiedSinceHeader));
308310
}
309311
}
310312
/* Check "If-None-Match" header */
@@ -331,8 +333,7 @@ private static void GetCachedResponse(HttpContext context, HttpRequest request,
331333
/*
332334
* Send 304 Not Modified
333335
*/
334-
Debug.WriteLine("OutputCacheModuleEnter", "Hit, conditional request satisfied, status=304. Key=" + key +
335-
". Returning from OutputCacheModule::Enter");
336+
Debug.WriteLine(SR.OutputCacheModuleEnter, string.Format(SR.Hit_conditional_request_satisfied,key) +"OutputCacheModule::Enter");
336337
if (response.HeadersWritten) {
337338
response.ClearHeaders();
338339
}
@@ -370,8 +371,8 @@ private async Task<bool> CheckHeadersToDetermineAcceptCachedCopy(string key, Htt
370371
string[] cacheDirectives = request.Headers["Cache-Control"].Split(s_fieldSeparators);
371372
foreach (string directive in cacheDirectives) {
372373
if (directive == "no-cache" || directive == "no-store") {
373-
Debug.WriteLine("OutputCache Module Async Enter",
374-
"Skipping lookup because of Cache-Control: no-cache or no-store directive. Returning from OutputCacheModule::Enter");
374+
Debug.WriteLine(SR.OutputCacheModuleEnter,
375+
SR.Skipping_lookup_because_of_Cache_Control_no_cache_or_no_store_directive + "OutputCacheModule::Enter");
375376
return true;
376377
}
377378
if (directive.StartsWith("max-age=")) {
@@ -393,8 +394,8 @@ private async Task<bool> CheckHeadersToDetermineAcceptCachedCopy(string key, Htt
393394
if (age < maxage) {
394395
continue;
395396
}
396-
Debug.WriteLine("OutputCacheModuleEnter",
397-
"Not returning found item due to Cache-Control: max-age directive. Returning from OutputCacheModule::Enter");
397+
Debug.WriteLine(SR.OutputCacheModuleEnter,
398+
SR.Not_returning_found_item_due_to_Cache_Control_max_age_directive + "OutputCacheModule::Enter");
398399
return true;
399400
}
400401
if (!directive.StartsWith("min-fresh=")) {
@@ -416,8 +417,8 @@ private async Task<bool> CheckHeadersToDetermineAcceptCachedCopy(string key, Htt
416417
if (fresh >= minfresh) {
417418
continue;
418419
}
419-
Debug.WriteLine("OutputCacheModuleEnter",
420-
"Not returning found item due to Cache-Control: min-fresh directive. Returning from OutputCacheModule::Enter");
420+
Debug.WriteLine(SR.OutputCacheModuleEnter,
421+
SR.Not_returning_found_item_due_to_Cache_Control_min_fresh_directive + "OutputCacheModule::Enter");
421422
return true;
422423
}
423424
}
@@ -429,8 +430,8 @@ private async Task<bool> CheckHeadersToDetermineAcceptCachedCopy(string key, Htt
429430
if (!pragmaDirectives.Any(t => t == null || t == "no-cache")) {
430431
return false;
431432
}
432-
Debug.WriteLine("OutputCacheModuleEnter",
433-
"Skipping lookup because of Pragma: no-cache directive. Returning from OutputCacheModule::Enter");
433+
Debug.WriteLine(SR.OutputCacheModuleEnter,
434+
SR.Skipping_lookup_because_of_Pragma_no_cache_directive + " OutputCacheModule::Enter");
434435
return true;
435436
}
436437
if (settings.ValidationCallbackInfo == null || !settings.ValidationCallbackInfo.Any()) {
@@ -445,9 +446,8 @@ private async Task<bool> CheckHeadersToDetermineAcceptCachedCopy(string key, Htt
445446
vci.Key(context, vci.Value, ref validationStatus);
446447
switch (validationStatus) {
447448
case HttpValidationStatus.Invalid:
448-
Debug.WriteLine("OutputCacheModuleEnter",
449-
"Output cache item found but callback invalidated it. key=" + key +
450-
". Returning from OutputCacheModule::Enter");
449+
Debug.WriteLine(SR.OutputCacheModuleEnter,
450+
string.Format(SR.Output_cache_item_found_but_callback_invalidated_it,key) + " OutputCacheModule::Enter");
451451

452452
await _outputCacheHelper.Remove(key, context);
453453
return true;
@@ -457,18 +457,16 @@ private async Task<bool> CheckHeadersToDetermineAcceptCachedCopy(string key, Htt
457457
case HttpValidationStatus.Valid:
458458
break;
459459
default:
460-
Debug.WriteLine("OutputCacheModuleEnter",
461-
"Invalid validation status, ignoring it, status=" + validationStatus +
462-
". Key=" + key);
460+
Debug.WriteLine(SR.OutputCacheModuleEnter,
461+
string.Format(SR.Invalid_validation_status, validationStatus, key));
463462
validationStatus = validationStatusFinal;
464463
break;
465464
}
466465
}
467466

468467
if (validationStatusFinal == HttpValidationStatus.IgnoreThisRequest) {
469-
Debug.WriteLine("OutputCacheModuleEnter",
470-
"Output cache item found but callback status is IgnoreThisRequest. Key=" + key +
471-
". Returning from OutputCacheModule::Enter");
468+
Debug.WriteLine(SR.OutputCacheModuleEnter,
469+
string.Format(SR.Callback_status_is_IgnoreThisRequest, key) + " OutputCacheModule::Enter");
472470
return true;
473471
}
474472

@@ -485,7 +483,8 @@ private static bool IsValidHttpMethod(HttpRequest request) {
485483
case "POST":
486484
break;
487485
default:
488-
Debug.WriteLine("Http method not GET, POST, or HEAD. Returning from OutputCacheModule::Enter");
486+
Debug.WriteLine("Http "
487+
+SR.method_is_not + "GET, POST, or HEAD."+ SR.Returning_from + " OutputCacheModule::Enter");
489488
return false;
490489
}
491490
return true;
@@ -503,10 +502,10 @@ private async Task<CachedItem> CheckCacheVaryAsync(CachedVary cachedVary, HttpCo
503502
*
504503
* Skip this step if it's a VaryByNone vary policy.
505504
*/
506-
string key = await OutputCacheHelper.CreateOutputCachedItemKeyAsync(context, cachedVary);
505+
string key = OutputCacheHelper.CreateOutputCachedItemKeyAsync(context, cachedVary);
507506
if (key == null) {
508-
Debug.WriteLine("OutputCacheModuleEnter",
509-
"Miss, key could not be created for vary-by item. Returning from OutputCacheModule::Enter");
507+
Debug.WriteLine(SR.OutputCacheModuleEnter,
508+
string.Format(SR.Miss_key_could_not_be_created_for_varyby_item,"Vary-By") + " OutputCacheModule::Enter");
510509
return new CachedItem {DoReturn = true, Item = null};
511510
}
512511
if (cachedVary.ContentEncodings == null) {
@@ -563,15 +562,15 @@ private static bool CheckHasQueryStringOrFormPost(HttpRequest request, string ke
563562
if (cachedVary == null && !settings.IgnoreParams) {
564563
// This cached output has no vary policy, so make sure it doesn't have a query string or form post.
565564
if (request.HttpMethod == "POST") {
566-
Debug.WriteLine("OutputCacheModuleEnter",
567-
"Output cache item found but method is POST and no VaryByParam specified. Key=" + key +
568-
". Returning from OutputCacheModule::Enter");
565+
Debug.WriteLine(SR.OutputCacheModuleEnter,
566+
string.Format(SR.Method_is_POST_and_no_VaryByParam_specified, "POST", "VaryByParam", key) +
567+
" OutputCacheModule::Enter");
569568
return true;
570569
}
571570
if (request.QueryString.Count > 0) {
572-
Debug.WriteLine("OutputCacheModuleEnter",
573-
"Output cache item found but contains a querystring and no VaryByParam specified. Key=" + key +
574-
". Returning from OutputCacheModule::Enter");
571+
Debug.WriteLine(SR.OutputCacheModuleEnter,
572+
string.Format(SR.Contains_querystring_and_no_VaryByParam_specified, " querystring ", " VaryByParam ", key) +
573+
" OutputCacheModule::Enter");
575574
return true;
576575
}
577576
}
@@ -582,9 +581,9 @@ private static bool CheckHasQueryStringOrFormPost(HttpRequest request, string ke
582581
if (!rangeHeader.StartsWith("bytes", StringComparison.OrdinalIgnoreCase)) {
583582
return false;
584583
}
585-
Debug.WriteLine("OutputCacheModuleEnter",
586-
"Output cache item found but this is a Range request and IgnoreRangeRequests is true. Key=" + key +
587-
". Returning from OutputCacheModule::Enter");
584+
Debug.WriteLine(SR.OutputCacheModuleEnter,
585+
string.Format(SR.Range_request_and_IgnoreRangeRequests_is_true, " Range request ", " IgnoreRangeRequests ", key) +
586+
" OutputCacheModule::Enter");
588587
// Don't record this as a cache miss. The response for a range request is not cached, and so
589588
// we don't want to pollute the cache hit/miss ratio.
590589
return true;

0 commit comments

Comments
 (0)