VirtualPathProvider.GetCacheDependency(String, IEnumerable, DateTime) Método

Definição

Cria uma dependência de cache com base nos caminhos virtuais especificados.

public:
 virtual System::Web::Caching::CacheDependency ^ GetCacheDependency(System::String ^ virtualPath, System::Collections::IEnumerable ^ virtualPathDependencies, DateTime utcStart);
public virtual System.Web.Caching.CacheDependency GetCacheDependency (string virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart);
abstract member GetCacheDependency : string * System.Collections.IEnumerable * DateTime -> System.Web.Caching.CacheDependency
override this.GetCacheDependency : string * System.Collections.IEnumerable * DateTime -> System.Web.Caching.CacheDependency
Public Overridable Function GetCacheDependency (virtualPath As String, virtualPathDependencies As IEnumerable, utcStart As DateTime) As CacheDependency

Parâmetros

virtualPath
String

O caminho para o recurso virtual primário.

virtualPathDependencies
IEnumerable

Uma matriz de caminhos para outros recursos exigidos pelo recurso virtual primário.

utcStart
DateTime

A hora UTC em que os recursos virtuais foram lidos.

Retornos

CacheDependency

Um objeto CacheDependency para os recursos virtuais especificados.

Exemplos

O exemplo de código a seguir implementa o GetCacheDependency método para uma classe personalizada VirtualPathProvider . Para obter o código completo necessário para executar o exemplo, consulte a seção Exemplo do tópico de visão geral da VirtualPathProvider classe.

public override CacheDependency GetCacheDependency(
  string virtualPath, 
  System.Collections.IEnumerable virtualPathDependencies, 
  DateTime utcStart)
{
  if (IsPathVirtual(virtualPath))
  {
    System.Collections.Specialized.StringCollection fullPathDependencies = null;

    // Get the full path to all dependencies.
    foreach (string virtualDependency in virtualPathDependencies)
    {
      if (fullPathDependencies == null)
        fullPathDependencies = new System.Collections.Specialized.StringCollection();

      fullPathDependencies.Add(virtualDependency);
    }
    if (fullPathDependencies == null)
      return null;

    // Copy the list of full-path dependencies into an array.
    string[] fullPathDependenciesArray = new string[fullPathDependencies.Count];
    fullPathDependencies.CopyTo(fullPathDependenciesArray, 0);
    // Copy the virtual path into an array.
    string[] virtualPathArray = new string[1];
    virtualPathArray[0] = virtualPath;

    return new CacheDependency(virtualPathArray, fullPathDependenciesArray, utcStart);
  }
  else
        {
            return Previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
        }
    }
Public Overrides Function GetCacheDependency(ByVal virtualPath As String, ByVal virtualPathDependencies As IEnumerable, ByVal utcStart As Date) As CacheDependency
  If (IsPathVirtual(virtualPath)) Then

    Dim fullPathDependencies As System.Collections.Specialized.StringCollection
    fullPathDependencies = Nothing

    ' Get the full path to all dependencies.
    For Each virtualDependency As String In virtualPathDependencies
      If fullPathDependencies Is Nothing Then
        fullPathDependencies = New System.Collections.Specialized.StringCollection
      End If

      fullPathDependencies.Add(virtualDependency)
    Next

    If fullPathDependencies Is Nothing Then
      Return Nothing
    End If

    Dim fullPathDependenciesArray As String()
    fullPathDependencies.CopyTo(fullPathDependenciesArray, 0)

    Return New CacheDependency(fullPathDependenciesArray, utcStart)
  Else
    Return Previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart)
  End If
End Function

Comentários

A implementação padrão do GetCacheDependency método retorna null. Para armazenar recursos virtuais em cache para uso posterior, você deve substituir o GetCacheDependency método ou o GetFileHash método.

Aplica-se a