Created
December 20, 2019 07:30
-
-
Save ouzdev/3e975563164d10d2d47419565f792ceb to your computer and use it in GitHub Desktop.
.NET Web Cache sınıfının kullanılması
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MyEvernote.BusinessLayer; | |
using MyEvernote.Entities; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Helpers; | |
namespace MyEvernote.WebApp.Models | |
{ | |
public class CacheHelper | |
{ | |
public static List<Category> GetCategoriesFromCache()//List kategori tipinde metod oluşturdum. | |
{ | |
var result = WebCache.Get("category-cache"); // WebCache sınıfının Get metodunu kullanarak category-cache adında key belirledim. Ve bu dönen değeri resulta atadım. | |
if (result == null) // Eğer result null ise yani bir değere sahip değilse. | |
{ | |
CategoryManager categoryManager = new CategoryManager(); // Kategori manager dan bir nesene ürettim ve List metodunu kullarak ilgili değerleri resulta atadım. | |
result = categoryManager.List(); | |
WebCache.Set("category-cache",result, 20, true); // Bu resulttaki değerleri cache aktardım | |
} | |
return result; // result değişkenini döndürdüm. | |
} | |
static public void RemoveCategoriesFromCache() | |
{ | |
Remove("category-cache"); // Cache'i boşalttım. | |
} | |
static public void Remove(string key) | |
{ | |
WebCache.Remove(key); // Burada ise gelen string türde key değişkenini kullanarak boşaltma yaptım. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment