del método WebPart.PartCacheWrite

Almacena el valor especificado del tipo especificado de almacenamiento en la memoria caché de elementos Web.

Espacio de nombres:  Microsoft.SharePoint.WebPartPages
Ensamblado:  Microsoft.SharePoint (en Microsoft.SharePoint.dll)

Sintaxis

'Declaración
Protected Sub PartCacheWrite ( _
    storage As Storage, _
    key As String, _
    value As Object, _
    timeout As TimeSpan _
)
'Uso
Dim storage As Storage
Dim key As String
Dim value As Object
Dim timeout As TimeSpan

Me.PartCacheWrite(storage, key, value, _
    timeout)
protected void PartCacheWrite(
    Storage storage,
    string key,
    Object value,
    TimeSpan timeout
)

Parámetros

  • storage
    Tipo: Microsoft.SharePoint.WebPartPages.Storage

    Un valor de Storage que especifica el tipo de almacenamiento en la memoria caché de elementos Web donde se almacena un valor. Los valores posibles son Personal y Shared. Especificación de None almacena nada.

  • key
    Tipo: System.String

    El nombre que se utilizará como la clave para el valor de deben almacenarse en la memoria caché de elementos Web.

  • value
    Tipo: System.Object

    System.Object que contiene el valor que se va a almacenar.

  • timeout
    Tipo: System.TimeSpan

    System.TimeSpan que especifica el período durante el cual PartCacheWrite intenta escribir un valor.

Comentarios

Si la CacheType es CacheObject, cualquier objeto puede almacenarse en la memoria caché. Si la CacheType es Database, el objeto debe estar marcado como serializable (System.SerializableAttribute).

Ejemplos

En el ejemplo de código siguiente se muestra un elemento Web que se almacena en caché y muestra la hora cuando se representa por primera vez y proporciona un botón para actualizar la memoria caché de elementos Web con la hora actual.

Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Xml.Serialization
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Utilities
Imports Microsoft.SharePoint.WebPartPages

Namespace WebPartLibrary1
    <DefaultProperty("Text"), _
    ToolboxData("<{0}:CacheSample runat=server></{0}:CacheSample>"), _
    XmlRoot([Namespace] := "WebPartLibrary1")>
   Public Class CacheSample
      
      Inherits Microsoft.SharePoint.WebPartPages.WebPart
      Private refreshButton As Button
            
      Public Sub New()
         AddHandler Me.PreRender, AddressOf UpdateCache
      End Sub
            
      Protected Overrides Sub CreateChildControls()
         refreshButton = New Button()
         refreshButton.Text = "Refresh Cache"
         AddHandler refreshButton.Click, AddressOf refreshButton_click
         Me.Controls.Add(refreshButton)
      End Sub
            
      Public Sub UpdateCache(o As Object, e As System.EventArgs)
         
         If Me.PartCacheRead(Storage.Shared, "cacheKey") Is Nothing Then
            Me.PartCacheWrite(Storage.Shared, "cacheKey", fetchData(), TimeSpan.FromSeconds(10))
         End If
      End Sub
            
      Private Sub refreshButton_click(o As Object, e As System.EventArgs)
         Me.PartCacheInvalidate(Storage.Shared, "cacheKey")
      End Sub
            
      Protected Overrides Sub RenderWebPart(output As HtmlTextWriter)
         output.Write("Cache Value: ")
         output.Write((PartCacheRead(Storage.Shared, "cacheKey") + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"))
         Me.RenderChildren(output)
      End Sub
            
      Private Function fetchData() As String
         Return DateTime.Now.ToLongTimeString()
      End Function
   End Class
End Namespace
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;

namespace WebPartLibrary1
{
    /// <summary>
    /// Summary description for CacheSample.
    /// </summary>
    [DefaultProperty("Text"),
        ToolboxData("<{0}:CacheSample runat=server></{0}:CacheSample>"),
        XmlRoot(Namespace="WebPartLibrary1")]

    public class CacheSample : Microsoft.SharePoint.WebPartPages.WebPart
    {
        Button refreshButton;

        public CacheSample()
        {
            this.PreRender+=new EventHandler(UpdateCache);
        }

        protected override void CreateChildControls()
        {
            refreshButton = new Button();
            refreshButton.Text="Refresh Cache";
            refreshButton.Click+=new EventHandler(refreshButton_click);
            this.Controls.Add(refreshButton);
        }

        public void UpdateCache(object o, System.EventArgs e)
        {

            if(this.PartCacheRead(Storage.Shared,"cacheKey") == null)
            {
                this.PartCacheWrite(Storage.Shared,"cacheKey", fetchData(), TimeSpan.FromSeconds(10));
            }
        }

        private void refreshButton_click(object o, System.EventArgs e)
        {
            this.PartCacheInvalidate(Storage.Shared, "cacheKey");
        }

        protected override void RenderWebPart(HtmlTextWriter output)
        {
            output.Write("Cache Value: ");
            output.Write(PartCacheRead(Storage.Shared,"cacheKey")+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
            this.RenderChildren(output);
        }

        private string fetchData()
        {
            return DateTime.Now.ToLongTimeString();
        }
    }
}
               

Vea también

Referencia

clase WebPart

Miembros WebPart

Espacio de nombres Microsoft.SharePoint.WebPartPages