Поиск…


Кэш данных

ASP.Net предоставляет API Cache для хранения данных в кэше для последующего поиска.

Начиная

Сохранить строку

   Cache["key"]="value";

Получить строку

var value="";
if (Cache["key"] != null)
   value = Cache["key"].ToString();

Вы также можете использовать методы « Добавить» или « Вставить» .

protected void Page_Load( object sender, EventArgs e)
{
    if ( this.IsPostBack )
    {
        label1.Text + = "Page is posted back";
    }
    else
    {
        label1.Text + = "Page is created";
    }
    
    if ( Cache [ "item"] == null )
    {
        label1.Text + = "New item is created";
        DateTime item = DateTime.Now;
        label1.Text + = "Item is stored";
        Cache.Insert ( "item", item, null );
        DateTime.Now.AddSeconds ( 20 ), TimeSpan.Zero;
    }

    else
    {
        label1.Text + = "Item is accesses";
        DateTime item = ( DateTime) Cache [ "item" ];
        label1.Text + = "Time is: " + item.ToString();
        label1.Text + = <br/>";
    }
    
    label1.Text + = "<br/>";
}


Modified text is an extract of the original Stack Overflow Documentation
Лицензировано согласно CC BY-SA 3.0
Не связан с Stack Overflow