The Labs \ Source Viewer \ SSCLI \ System.Net.Cache \ RequestCache

  1. //------------------------------------------------------------------------------
  2. // <copyright file="RequestCache.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. /*++   
  16. Abstract:
  17.     The file specifies interfaces used to communicate with Request Caching subsystem.
  18. Author:
  19.     Alexei Vopilov    21-Dec-2002
  20. Revision History:
  21.     Jan 25 2004 - Changed the visibility of the class from public to internal.
  22. --*/
  23. namespace System.Net.Cache
  24. {
  25.     using System;
  26.     using System.Diagnostics;
  27.     using System.Text;
  28.     using System.IO;
  29.     using System.Collections.Specialized;
  30.     using System.Threading;
  31.    
  32.     // The class specifies the contract for a caching storage to participate in the caching protocol.
  33.     // The required functionality is to retrieve cached data and update cache based on a string as a Key.
  34.     // It is also assumed that cache does storage quota management so it can remove expired cached entries under limited space conditions.
  35.     // Note that no implementation methods should block as there is no Async API exposed by this type.
  36.     internal abstract class RequestCache
  37.     {
  38.         static internal readonly char[] LineSplits = new char[] {'\r', '\n'};
  39.        
  40.         private bool _IsPrivateCache;
  41.         private bool _CanWrite;
  42.        
  43.         protected RequestCache(bool isPrivateCache, bool canWrite)
  44.         {
  45.             _IsPrivateCache = isPrivateCache;
  46.             _CanWrite = canWrite;
  47.         }
  48.        
  49.         internal bool IsPrivateCache {
  50.             get { return _IsPrivateCache; }
  51.         }
  52.         internal bool CanWrite {
  53.             get { return _CanWrite; }
  54.         }
  55.        
  56.        
  57.         // Returns a read data stream and metadata associated with a cached entry.
  58.         // Returns Stream.Null if there is no entry found.
  59.         // <remarks> An opened cache entry be preserved until the stream is closed. </remarks>
  60.         //
  61.         internal abstract Stream Retrieve(string key, out RequestCacheEntry cacheEntry);
  62.        
  63.         // Returns a write cache stream associated with the string Key.
  64.         // Passed parameters allow cache to update an entry metadata accordingly.
  65.         // <remarks> The commit operation should happen on the stream closure. </remarks>
  66.         //
  67.         internal abstract Stream Store(string key, long contentLength, DateTime expiresUtc, DateTime lastModifiedUtc, TimeSpan maxStale, StringCollection entryMetadata, StringCollection systemMetadata);
  68.        
  69.         //
  70.         // Removes an entry from the cache.
  71.         //
  72.         internal abstract void Remove(string key);
  73.        
  74.         //
  75.         // Updates only metadata associated with a cached entry.
  76.         //
  77.         internal abstract void Update(string key, DateTime expiresUtc, DateTime lastModifiedUtc, DateTime lastSynchronizedUtc, TimeSpan maxStale, StringCollection entryMetadata, StringCollection systemMetadata);
  78.        
  79.        
  80.         //
  81.         // Does not throw on failure
  82.         internal abstract bool TryRetrieve(string key, out RequestCacheEntry cacheEntry, out Stream readStream);
  83.         //
  84.         // Does not throw on failure
  85.         internal abstract bool TryStore(string key, long contentLength, DateTime expiresUtc, DateTime lastModifiedUtc, TimeSpan maxStale, StringCollection entryMetadata, StringCollection systemMetadata, out Stream writeStream);
  86.         //
  87.         // Does not throw on failure
  88.         internal abstract bool TryRemove(string key);
  89.         //
  90.         // Does not throw on failure
  91.         internal abstract bool TryUpdate(string key, DateTime expiresUtc, DateTime lastModifiedUtc, DateTime lastSynchronizedUtc, TimeSpan maxStale, StringCollection entryMetadata, StringCollection systemMetadata);
  92.        
  93.         //
  94.         // This can be looked as a design hole since we have to keep the entry
  95.         // locked for the case when we want to update that previously retrieved entry.
  96.         // I think RequestCache contract should allow to detect that a new physical cache entry
  97.         // does not match to the "entry being updated" and so to should ignore updates on replaced entries.
  98.         //
  99.         internal abstract void UnlockEntry(Stream retrieveStream);
  100.        
  101.     }
  102. }

Developer Fusion