Skip to content

Commit

Permalink
redis final state
Browse files Browse the repository at this point in the history
  • Loading branch information
Mert Güney committed Sep 26, 2021
0 parents commit 691f4ff
Show file tree
Hide file tree
Showing 575 changed files with 163,241 additions and 0 deletions.
Binary file not shown.
1,047 changes: 1,047 additions & 0 deletions .vs/UdemyRedisInMemory/config/applicationhost.config

Large diffs are not rendered by default.

Binary file added .vs/UdemyRedisInMemory/v16/.suo
Binary file not shown.
37 changes: 37 additions & 0 deletions IDistributedCacheRedisApp.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using IDistributedCacheRedisApp.Web.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

namespace IDistributedCacheRedisApp.Web.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}

public IActionResult Index()
{
return View();
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
73 changes: 73 additions & 0 deletions IDistributedCacheRedisApp.Web/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using IDistributedCacheRedisApp.Web.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IDistributedCacheRedisApp.Web.Controllers
{
public class ProductsController : Controller
{
private readonly IDistributedCache _distributedCache;
public ProductsController(IDistributedCache distributedCache)
{
_distributedCache = distributedCache;
}
public IActionResult Index()
{
DistributedCacheEntryOptions cacheEntryOptions = new DistributedCacheEntryOptions();
cacheEntryOptions.AbsoluteExpiration = DateTime.Now.AddMinutes(1);
//_distributedCache.SetString("name", "guneymert", cacheEntryOptions);

Product product = new Product { Id = 1, Name = "Kalem", Price = 100 };
string jsonProduct = JsonConvert.SerializeObject(product);
//_distributedCache.SetString("product:1", jsonProduct, cacheEntryOptions);
Byte[] byteProduct = Encoding.UTF8.GetBytes(jsonProduct);
_distributedCache.Set("product:1", byteProduct);


return View();
}
public IActionResult Show()
{
//string name = _distributedCache.GetString("name");
//ViewBag.name = name;

//string jsonProduct = _distributedCache.GetString("product:1");


Byte[] byteProduct = _distributedCache.Get("product:1");
string jsonProduct = Encoding.UTF8.GetString(byteProduct);

Product p = JsonConvert.DeserializeObject<Product>(jsonProduct);

ViewBag.product = p;

return View();
}
public IActionResult Remove()
{
_distributedCache.Remove("name");
return View();
}
public IActionResult ImageCache()
{
string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/a.jpg");
Byte[] imageByte = System.IO.File.ReadAllBytes(path);
_distributedCache.Set("image", imageByte);
return View();
}
public IActionResult ImageUrl()
{
Byte[] imageByte = _distributedCache.Get("image");


return File(imageByte, "image/jpg");
}
}
}
12 changes: 12 additions & 0 deletions IDistributedCacheRedisApp.Web/IDistributedCacheRedisApp.Web.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="3.1.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.5" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
<View_SelectedScaffolderID>RazorViewScaffolder</View_SelectedScaffolderID>
<View_SelectedScaffolderCategoryPath>root/Common/MVC/View</View_SelectedScaffolderCategoryPath>
<WebStackScaffolding_ViewDialogWidth>650</WebStackScaffolding_ViewDialogWidth>
<WebStackScaffolding_IsLayoutPageSelected>True</WebStackScaffolding_IsLayoutPageSelected>
<WebStackScaffolding_IsPartialViewSelected>False</WebStackScaffolding_IsPartialViewSelected>
<WebStackScaffolding_IsReferencingScriptLibrariesSelected>False</WebStackScaffolding_IsReferencingScriptLibrariesSelected>
<WebStackScaffolding_LayoutPageFile />
</PropertyGroup>
</Project>
11 changes: 11 additions & 0 deletions IDistributedCacheRedisApp.Web/Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace IDistributedCacheRedisApp.Web.Models
{
public class ErrorViewModel
{
public string RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}
14 changes: 14 additions & 0 deletions IDistributedCacheRedisApp.Web/Models/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace IDistributedCacheRedisApp.Web.Models
{
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public int Price { get; set; }
}
}
26 changes: 26 additions & 0 deletions IDistributedCacheRedisApp.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace IDistributedCacheRedisApp.Web
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
27 changes: 27 additions & 0 deletions IDistributedCacheRedisApp.Web/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:37690",
"sslPort": 44356
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IDistributedCacheRedisApp.Web": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
63 changes: 63 additions & 0 deletions IDistributedCacheRedisApp.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace IDistributedCacheRedisApp.Web
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{

services.AddStackExchangeRedisCache(opts =>
{
opts.Configuration = "localhost:6379";
});

services.AddControllersWithViews();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
8 changes: 8 additions & 0 deletions IDistributedCacheRedisApp.Web/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@{
ViewData["Title"] = "Home Page";
}

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
6 changes: 6 additions & 0 deletions IDistributedCacheRedisApp.Web/Views/Home/Privacy.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@{
ViewData["Title"] = "ImageCache";
}

<h1>ImageCache</h1>

8 changes: 8 additions & 0 deletions IDistributedCacheRedisApp.Web/Views/Products/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

@{
ViewData["Title"] = "Index";
}

<h1>Index</h1>
<img src="/products/ImageUrl" />

7 changes: 7 additions & 0 deletions IDistributedCacheRedisApp.Web/Views/Products/Remove.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@{
ViewData["Title"] = "Remove";
}

<h1>Remove</h1>

9 changes: 9 additions & 0 deletions IDistributedCacheRedisApp.Web/Views/Products/Show.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

@{
ViewData["Title"] = "Show";
Product p = ViewBag.product as Product;
}

<h1>Show</h1>
<h1>@p.Id => @p.Name</h1>

25 changes: 25 additions & 0 deletions IDistributedCacheRedisApp.Web/Views/Shared/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@model ErrorViewModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
Loading

0 comments on commit 691f4ff

Please sign in to comment.