Skip to content

Instantly share code, notes, and snippets.

@ouzdev
Created December 20, 2019 07:30
Show Gist options
  • Save ouzdev/3e975563164d10d2d47419565f792ceb to your computer and use it in GitHub Desktop.
Save ouzdev/3e975563164d10d2d47419565f792ceb to your computer and use it in GitHub Desktop.
.NET Web Cache sınıfının kullanılması
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