Files
AzureTableStorageCache/src/AzureTableStorageCacheSample/Controllers/HomeController.cs
Tommy Parnell b3b92d3d59 init
2015-11-15 09:26:30 -05:00

52 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.Framework.Caching.Distributed;
namespace AzureTableStorageCache.Sample.Controllers
{
public class HomeController : Controller
{
private readonly IDistributedCache cacheMechanism;
public HomeController(IDistributedCache cacheMechanism)
{
this.cacheMechanism = cacheMechanism;
}
public async Task<IActionResult> Index()
{
var data = await cacheMechanism.GetAsync("awesomeRecord");
var result = string.Empty;
if(data != null)
{
result = Encoding.UTF32.GetString(data);
}
return View(result);
}
public async Task<IActionResult> AddCache()
{
cacheMechanism.SetAsync("awesomeRecord", Encoding.UTF32.GetBytes("Im Awesome"));
ViewData["Message"] = "Your application description page.";
return RedirectToAction("Index");
}
public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";
return View();
}
public IActionResult Error()
{
return View("~/Views/Shared/Error.cshtml");
}
}
}