Ejemplo n.º 1
0
        public IActionResult CacheSlidingExpiration(string value)
        {
            var cacheEntryOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(new TimeSpan(0, 0, 30));
            var m = new CachingModel(value, true);

            _cache.Set(SCKEY, m, cacheEntryOptions);
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public override object GetData(ITabContext context)
        {
            var timelineMessages = context.GetMessages <ITimelineMessage>().Where(m => m.EventName.StartsWith("WAZCache:"));

            var model = new CachingModel();

            if (timelineMessages != null)
            {
                // TODO: build useful data from this
                model.TotalSuccessful = timelineMessages.Count();
                return(model);
            }

            return("No cache has been utilized for this request.");
        }
Ejemplo n.º 3
0
        #pragma warning disable 1998
        public async override global::System.Threading.Tasks.Task ExecuteAsync()
        {
#line 1 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"

            ViewData["Title"] = "Home Page";
            CachingModel a = (CachingModel)ViewData["ABS"];
            CachingModel b = (CachingModel)ViewData["SLID"];

#line default
#line hidden
            BeginContext(152, 117, true);
            WriteLiteral("<style>\r\n    .half { width: 50%; float:left; }\r\n</style>\r\n<div class=\"text-center\">\r\n    <div>\r\n        Current Time ");
            EndContext();
            BeginContext(270, 23, false);
#line 11 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
            Write(DateTime.Now.ToString());

#line default
#line hidden
            EndContext();
            BeginContext(293, 148, true);
            WriteLiteral("\r\n    </div>\r\n    <div class=\"half\">\r\n        <h1 class=\"display-4\">Absolute Expiration</h1>\r\n        <p style=\"font-weight: bold;\">Cached Value: \r\n");
            EndContext();
#line 16 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
            if (a == null)
            {
#line default
#line hidden
                BeginContext(500, 4, true);
                WriteLiteral("NULL");
                EndContext();
#line 17 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
            }
            else
            {
#line default
#line hidden
                BeginContext(582, 7, false);
#line 20 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
                Write(a.Value);

#line default
#line hidden
                EndContext();
                BeginContext(589, 11, true);
                WriteLiteral(" (Expires: ");
                EndContext();
                BeginContext(601, 16, false);
#line 20 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
                Write(a.ExpirationDate);

#line default
#line hidden
                EndContext();
                BeginContext(617, 1, true);
                WriteLiteral(")");
                EndContext();
#line 20 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
            }

#line default
#line hidden
            BeginContext(658, 39, true);
            WriteLiteral("        </p>\r\n        <p>\r\n            ");
            EndContext();
            BeginContext(697, 252, false);
            __tagHelperExecutionContext = __tagHelperScopeManager.Begin("form", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "c33fc0c422ead650ffb7f531dd8ce045128624057013", async() => {
                BeginContext(780, 18, true);
                WriteLiteral("\r\n                ");
                EndContext();
                BeginContext(799, 33, false);
#line 25 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
                Write(Html.Label("Set New Cache Value"));

#line default
#line hidden
                EndContext();
                BeginContext(832, 18, true);
                WriteLiteral("\r\n                ");
                EndContext();
                BeginContext(851, 21, false);
#line 26 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
                Write(Html.TextBox("Value"));

#line default
#line hidden
                EndContext();
                BeginContext(872, 70, true);
                WriteLiteral("\r\n                <input type=\"submit\" value=\"Submit\" />\r\n            ");
                EndContext();
            }
                                                                        );
            __Microsoft_AspNetCore_Mvc_TagHelpers_FormTagHelper = CreateTagHelper <global::Microsoft.AspNetCore.Mvc.TagHelpers.FormTagHelper>();
            __tagHelperExecutionContext.Add(__Microsoft_AspNetCore_Mvc_TagHelpers_FormTagHelper);
            __Microsoft_AspNetCore_Mvc_TagHelpers_RenderAtEndOfFormTagHelper = CreateTagHelper <global::Microsoft.AspNetCore.Mvc.TagHelpers.RenderAtEndOfFormTagHelper>();
            __tagHelperExecutionContext.Add(__Microsoft_AspNetCore_Mvc_TagHelpers_RenderAtEndOfFormTagHelper);
            __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_0);
            __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_1);
            __Microsoft_AspNetCore_Mvc_TagHelpers_FormTagHelper.Method = (string)__tagHelperAttribute_2.Value;
            __tagHelperExecutionContext.AddTagHelperAttribute(__tagHelperAttribute_2);
            await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);

            if (!__tagHelperExecutionContext.Output.IsContentModified)
            {
                await __tagHelperExecutionContext.SetOutputContentAsync();
            }
            Write(__tagHelperExecutionContext.Output);
            __tagHelperExecutionContext = __tagHelperScopeManager.End();
            EndContext();
            BeginContext(949, 296, true);
            WriteLiteral(@"
        </p>
        <p>Setting/Updating this value will cache the value for exactly 30 seconds. After that, the cached value will be removed.</p>
    </div>
    <div class=""half"">
        <h1 class=""display-4"">Sliding Expiration</h1>
        <p style=""font-weight: bold;"">Cached Value: 
");
            EndContext();
#line 35 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
            if (b == null)
            {
#line default
#line hidden
                BeginContext(1304, 4, true);
                WriteLiteral("NULL");
                EndContext();
#line 36 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
            }
            else
            {
#line default
#line hidden
                BeginContext(1386, 7, false);
#line 39 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
                Write(b.Value);

#line default
#line hidden
                EndContext();
                BeginContext(1393, 11, true);
                WriteLiteral(" (Expires: ");
                EndContext();
                BeginContext(1405, 16, false);
#line 39 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
                Write(b.ExpirationDate);

#line default
#line hidden
                EndContext();
                BeginContext(1421, 1, true);
                WriteLiteral(")");
                EndContext();
#line 39 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
            }

#line default
#line hidden
            BeginContext(1462, 39, true);
            WriteLiteral("        </p>\r\n        <p>\r\n            ");
            EndContext();
            BeginContext(1501, 251, false);
            __tagHelperExecutionContext = __tagHelperScopeManager.Begin("form", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "c33fc0c422ead650ffb7f531dd8ce0451286240511378", async() => {
                BeginContext(1583, 18, true);
                WriteLiteral("\r\n                ");
                EndContext();
                BeginContext(1602, 33, false);
#line 44 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
                Write(Html.Label("Set New Cache Value"));

#line default
#line hidden
                EndContext();
                BeginContext(1635, 18, true);
                WriteLiteral("\r\n                ");
                EndContext();
                BeginContext(1654, 21, false);
#line 45 "f:\tfs\70-487 Examples\Views\MemoryCaching\Index.cshtml"
                Write(Html.TextBox("Value"));

#line default
#line hidden
                EndContext();
                BeginContext(1675, 70, true);
                WriteLiteral("\r\n                <input type=\"submit\" value=\"Submit\" />\r\n            ");
                EndContext();
            }
                                                                        );
            __Microsoft_AspNetCore_Mvc_TagHelpers_FormTagHelper = CreateTagHelper <global::Microsoft.AspNetCore.Mvc.TagHelpers.FormTagHelper>();
            __tagHelperExecutionContext.Add(__Microsoft_AspNetCore_Mvc_TagHelpers_FormTagHelper);
            __Microsoft_AspNetCore_Mvc_TagHelpers_RenderAtEndOfFormTagHelper = CreateTagHelper <global::Microsoft.AspNetCore.Mvc.TagHelpers.RenderAtEndOfFormTagHelper>();
            __tagHelperExecutionContext.Add(__Microsoft_AspNetCore_Mvc_TagHelpers_RenderAtEndOfFormTagHelper);
            __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_0);
            __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_3);
            __Microsoft_AspNetCore_Mvc_TagHelpers_FormTagHelper.Method = (string)__tagHelperAttribute_2.Value;
            __tagHelperExecutionContext.AddTagHelperAttribute(__tagHelperAttribute_2);
            await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);

            if (!__tagHelperExecutionContext.Output.IsContentModified)
            {
                await __tagHelperExecutionContext.SetOutputContentAsync();
            }
            Write(__tagHelperExecutionContext.Output);
            __tagHelperExecutionContext = __tagHelperScopeManager.End();
            EndContext();
            BeginContext(1752, 224, true);
            WriteLiteral("\r\n        </p>\r\n        <p>Setting/Updating this value will cache the value for exactly 30 seconds. However, if the page is refreshed before the cached value expires, the 30 seconds starts over.</p>\r\n    </div>    \r\n</div>\r\n");
            EndContext();
        }