VirtualPathProvider.GetCacheDependency(String, IEnumerable, DateTime) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
基於指定的虛擬路徑建立快取相依性。
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
參數
- virtualPath
- String
主要虛擬資源的路徑。
- virtualPathDependencies
- IEnumerable
主要虛擬資源所需之其他資源的路徑陣列。
- utcStart
- DateTime
UTC 時間,會在該期間讀取虛擬資源。
傳回
指定虛擬資源的 CacheDependency 物件。
範例
下列程式碼範例會 GetCacheDependency 實作自訂 VirtualPathProvider 類別的 方法。 如需執行範例所需的完整程式碼,請參閱類別概觀主題的 VirtualPathProvider 範例一節。
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
備註
方法的預設實作 GetCacheDependency 會 null
傳回 。 若要快取虛擬資源以供稍後使用,您必須覆寫 GetCacheDependency 方法或 GetFileHash 方法。