2016-06-11 09:59:24 -04:00
2015-11-15 09:26:30 -05:00
2016-06-10 20:59:18 -04:00
2016-06-10 20:59:18 -04:00
2015-11-15 09:18:30 -05:00
2016-06-10 21:17:07 -04:00

AspNetCache-AzureTableStorage

Use azure table storage for AspNet core 1.0 Distributed Cache.

Azure Table Storage is a very cheap, super fast key value store, and its much cheaper than the redis cluster in azure. This is not a true replacement for redis, and redis should be used if people have money, but this is designed to get people a very cheap cache in azure. Currently this doesn't actually support the dotnet core runtime, and won't until the Azure Storage client is updated to support core.

How to use

install-package AzureTableStorageCache

In your startup.cs


 public void ConfigureServices(IServiceCollection services)
        {
            services.AddAzureTableStorageCache("!!!CONNECTIONSTRINGHERE!!!", "tablename", "partitionKey");
            // Add framework services.
            services.AddMvc();
        }


Then in a controller just ask for an IDistributedCache in the constructor. Since this implements Microsoft's IDistributed cache, it could be easily swapped out for redis or another Distributed cache


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()
        {
            await cacheMechanism.SetAsync("awesomeRecord", Encoding.UTF32.GetBytes("Im Awesome"));
            ViewData["Message"] = "Your application description page.";

            return RedirectToAction("Index");
        }
}

Description
Use azure table storage for AspNet core 1.0 Distributed Cache (save money on redis in azure)
Readme MIT 150 KiB
Languages
C# 58.9%
HTML 37%
JavaScript 4.1%