OutputCacheLocation Enumeração
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Especifica os valores válidos para controlar a localização da resposta HTTP em cache de saída para um recurso.
public enum class OutputCacheLocation
public enum OutputCacheLocation
type OutputCacheLocation =
Public Enum OutputCacheLocation
- Herança
Campos
| Name | Valor | Description |
|---|---|---|
| Any | 0 | A cache de saída pode estar localizada no cliente do navegador (onde o pedido se originou), num servidor proxy (ou em qualquer outro servidor) que participe no pedido, ou no servidor onde o pedido foi processado. Este valor corresponde ao Public valor de enumeração. |
| Client | 1 | A cache de saída está localizada no cliente do navegador onde o pedido teve origem. Este valor corresponde ao Private valor de enumeração. |
| Downstream | 2 | A cache de saída pode ser armazenada em qualquer dispositivo compatível com cache HTTP 1.1, exceto o servidor de origem. Isto inclui servidores proxy e o cliente que fez o pedido. |
| Server | 3 | A cache de saída está localizada no servidor Web onde o pedido foi processado. Este valor corresponde ao Server valor de enumeração. |
| None | 4 | A cache de saída está desativada para a página solicitada. Este valor corresponde ao NoCache valor de enumeração. |
| ServerAndClient | 5 | A cache de saída pode ser armazenada apenas no servidor de origem ou no cliente solicitante. Os servidores proxy não podem armazenar em cache a resposta. Este valor corresponde à combinação dos Private valores de enumeração e Server . |
Exemplos
O exemplo de código seguinte demonstra como o valor do servidor é usado para especificar que a página deve ser armazenada em cache no servidor Web onde o pedido é processado.
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
// The following OutputCache directive uses the OutputCacheLocation.Server
// enumeration value to allow output caching only on the origin server.
<%@ outputcache duration="10" varybyparam="none" Location="Server" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<script language="C#" runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
DataSet ds = new DataSet();
FileStream fs = new FileStream(Server.MapPath("schemadata.xml"),FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
ds.ReadXml(reader);
fs.Close();
DataView Source = new DataView(ds.Tables[0]);
// Use the LiteralControl constructor to create a new
// instance of the class.
LiteralControl myLiteral = new LiteralControl();
// Set the LiteralControl.Text property to an HTML
// string and the TableName value of a data source.
myLiteral.Text = "<h6><font face=\"verdana\">Caching an XML Table: " + Source.Table.TableName + " </font></h6>";
MyDataGrid.DataSource = Source;
MyDataGrid.DataBind();
TimeMsg.Text = DateTime.Now.ToString("G");
}
</script>
<head runat="server">
<title>Using the OutputCacheLocation Enumeration </title>
</head>
<body>
<h6>Using the OutputCacheLocation Enumeration </h6>
<form id="form1" runat="server">
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="900"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding="3"
CellSpacing="0"
Font-Names="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false"
/>
<i>Page last generated on:</i> <asp:label id="TimeMsg" runat="server" />
</form>
</body>
</html>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
' The following OutputCache directive uses the OutputCacheLocation.Server
' enumeration value to allow output caching only on the origin server.
<%@ outputcache duration="10" varybyparam="none" Location="Server" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<script language="vb" runat="server">
Protected Sub Page_Load(Src As [Object], E As EventArgs)
Dim ds As New DataSet()
Dim fs As New FileStream(Server.MapPath("schemadata.xml"),FileMode.Open,FileAccess.Read)
Dim reader As New StreamReader(fs)
ds.ReadXml(reader)
fs.Close()
Dim [Source] As New DataView(ds.Tables(0))
MyDataGrid.DataSource = [Source]
MyDataGrid.DataBind()
TimeMsg.Text = DateTime.Now.ToString("G")
End Sub 'Page_Load
</script>
<head runat="server">
<title>Using the OutputCacheLocation Enumeration </title>
</head>
<body>
<h4>Using the OutputCacheLocation Enumeration </h4>
<form id="form1" runat="server">
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="900"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding="3"
CellSpacing="0"
Font-Names="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false"
/>
<i>Page last generated on:</i> <asp:label id="TimeMsg" runat="server" />
</form>
</body>
</html>
Observações
Os valores especificados por esta enumeração são usados quando se inclui uma @ OutputCache diretiva num ficheiro .aspx. Estes valores determinam a localização da cache para a saída da página. Para mais informações, consulte Cache ASP.NET Páginas.