Checkpoint

git-svn-id: svn://10.0.0.236/trunk@52867 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
fur%netscape.com
1999-11-05 21:58:37 +00:00
parent be87817fb0
commit c8cc3fe9b2
10 changed files with 287 additions and 458 deletions

View File

@@ -22,18 +22,16 @@ include <$(DEPTH)/config/config.mak>
EXPORTS = \
nsICacheManager.h \
nsICacheObject.h \
nsICachePref.h \
nsICacheModule.h \
$(NULL)
XPIDLSRCS = \
.\nsICachedNetData.idl \
.\nsINetDataCacheManager.idl \
.\nsINetDataCache.idl \
.\nsINetDataCacheRecord.idl \
.\nsINetDataDiskCache.idl \
.\nsICachedNetData.idl \
.\nsINetDataCacheRecord.idl
.\nsIStreamAsFile.idl \
$(NULL)
include <$(DEPTH)/config/rules.mak>

View File

@@ -1,57 +0,0 @@
#ifndef _nsICacheManger_H_
#define _nsICacheManger_H_
#include "nsISupports.h"
#include "nsICacheModule.h"
#include "nsICachePref.h"
// nsICacheManager {05A4BC00-3E1A-11d3-87EE-000629D01344}
#define NS_ICACHEMANAGER_IID \
{0x5a4bc00, 0x3e1a, 0x11d3, \
{0x87, 0xee, 0x0, 0x6, 0x29, 0xd0, 0x13, 0x44}}
// {B8B5D4E0-3F92-11d3-87EF-000629D01344}
#define NS_CACHEMANAGER_CID \
{0xb8b5d4e0, 0x3f92, 0x11d3, \
{0x87, 0xef, 0x0, 0x6, 0x29, 0xd0, 0x13, 0x44}}
class nsICacheManager : public nsISupports
{
public:
//Reserved modules
enum modules
{
MEM =0,
DISK=1
};
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICACHEMANAGER_IID) ;
NS_IMETHOD Contains(const char* i_url) const = 0 ;
NS_IMETHOD Entries(PRInt16 * n_Entries) const = 0 ;
NS_IMETHOD GetObj(const char* i_url, void ** o_Object) const = 0 ;
NS_IMETHOD GetModule(PRInt16 i_index, nsICacheModule** o_module) const = 0 ;
NS_IMETHOD GetDiskModule(nsICacheModule** o_module) const = 0 ;
NS_IMETHOD GetMemModule(nsICacheModule** o_module) const = 0 ;
NS_IMETHOD AddModule (PRInt16 * o_Index, nsICacheModule * pModule) = 0 ;
NS_IMETHOD GetPrefs(nsICachePref** o_Pref) const = 0 ;
NS_IMETHOD InfoAsHTML(char** o_Buffer) const = 0 ;
NS_IMETHOD IsOffline(PRBool * bOffline) const = 0 ;
NS_IMETHOD Offline(PRBool bSet) = 0 ;
NS_IMETHOD Remove(const char* i_url) = 0 ;
NS_IMETHOD WorstCaseTime(PRUint32 * o_Time) const = 0 ;
} ;
#endif

View File

@@ -1,108 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* nsCacheModule. A class that defines the way a cache module
* should be written. Its the super class for any new modules.
* Two sample modules derived from this one are nsMemModule and nsDiskModule.
*
* Gagan Saksena 02/03/98
*
*/
#ifndef nsICacheModule_h__
#define nsICacheModule_h__
#include <nsISupports.h>
#include "nsICacheObject.h"
#include "nsEnumeration.h"
// {5D51B24F-E6C2-11d1-AFE5-006097BFC036}
#define NS_ICACHEMODULE_IID \
{ 0x5d51b24f, 0xe6c2, 0x11d1, \
{ 0xaf, 0xe5, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
class nsICacheModule : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR (NS_ICACHEMODULE_IID);
NS_IMETHOD AddObject(nsICacheObject* i_pObject) = 0;
NS_IMETHOD ContainsURL(const char* i_url, PRBool* o_bContain) = 0;
NS_IMETHOD ContainsCacheObj(nsICacheObject* i_pObject, PRBool* o_bContain) = 0;
NS_IMETHOD Enable (PRBool i_bEnable) = 0;
NS_IMETHOD GetNumOfEntries (PRUint32* o_nEntries) = 0;
NS_IMETHOD GetEnumerator (nsEnumeration** o_enum) = 0;
/* Enumerations with a function pointer - TODO */
//TODO move to own interface for both Garbage Collection and Revalidation
NS_IMETHOD GarbageCollect (void) = 0;
NS_IMETHOD GetObjectByURL (const char* i_url, nsICacheObject** o_pObj) = 0;
NS_IMETHOD GetObjectByIndex (const PRUint32 i_index, nsICacheObject** o_pObj) = 0;
NS_IMETHOD GetStreamFor (const nsICacheObject* i_pObject, nsStream** o_pStream) = 0;
NS_IMETHOD IsEnabled (PRBool* o_bEnabled) = 0;
/* Can't do additions, deletions, validations, expirations */
NS_IMETHOD IsReadOnly (PRBool* o_bReadOnly) = 0;
NS_IMETHOD GetNextModule (nsICacheModule** o_pCacheModule) = 0;
NS_IMETHOD SetNextModule (nsICacheModule* i_pCacheModule) = 0;
NS_IMETHOD RemoveByURL (const char* i_url) = 0;
NS_IMETHOD RemoveByIndex (const PRUint32 i_index) = 0;
NS_IMETHOD RemoveByObject (nsICacheObject* i_pObject) = 0;
NS_IMETHOD RemoveAll (void) = 0;
NS_IMETHOD Revalidate (void) = 0;
NS_IMETHOD ReduceSizeTo (const PRUint32 i_newsize) = 0;
NS_IMETHOD GetSize (PRUint32* o_size) = 0;
NS_IMETHOD SetSize (const PRUint32 i_size) = 0;
NS_IMETHOD GetSizeInUse (PRUint32* o_size) = 0;
};
// {5D51B24E-E6C1-11d0-AFE5-006097BFC036}
#define NS_DISKMODULE_CID \
{ 0x5d51b24e, 0xe6c1, 0x11d0, \
{ 0xaf, 0xe5, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
// {5D51B250-E6C2-11d1-AFE5-006097BFC036}
#define NS_MEMMODULE_CID \
{ 0x5d51b250, 0xe6c2, 0x11d1, \
{ 0xaf, 0xe5, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
#endif

View File

@@ -1,106 +0,0 @@
#ifndef _NS_CACHEOBJECT_H_
#define _NS_CACHEOBJECT_H_
#include "nsISupports.h"
#include "nsStream.h"
#include "prtypes.h"
#include "prinrval.h"
// nsICacheObject {A2D9A8A0-414B-11d3-87EF-000629D01344}
#define NS_ICACHEOBJECT_IID \
{0xa2d9a8a0, 0x414b, 0x11d3, \
{0x87, 0xef, 0x0, 0x6, 0x29, 0xd0, 0x13, 0x44 }}
// nsCacheObject {A2D9A8A1-414B-11d3-87EF-000629D01344}
#define NS_CACHEOBJECT_CID \
{0xa2d9a8a1, 0x414b, 0x11d3, \
{0x87, 0xef, 0x0, 0x6, 0x29, 0xd0, 0x13, 0x44 }}
class nsICacheObject :public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICACHEOBJECT_IID);
/* Cache Object- check nsCacheObject.h for details on these functions */
/* This is added because we need to initialize a new cacheobject
NS_IMETHOD InitUrl(const char * i_url) = 0 ;
*/
NS_IMETHOD GetAddress(char ** Addr) const = 0 ;
NS_IMETHOD SetAddress(const char* i_Address) = 0 ;
NS_IMETHOD GetCharset(char ** CSet) const = 0 ;
NS_IMETHOD SetCharset(const char* i_CharSet) = 0 ;
NS_IMETHOD GetContentEncoding(char ** Encoding) const = 0 ;
NS_IMETHOD SetContentEncoding(const char* i_Encoding) = 0 ;
NS_IMETHOD GetContentLength(PRUint32 * CLeng) const = 0 ;
NS_IMETHOD SetContentLength(PRUint32 i_Len) = 0 ;
NS_IMETHOD GetContentType(char ** CType) const = 0 ;
NS_IMETHOD SetContentType(const char* i_Type) = 0 ;
NS_IMETHOD GetEtag(char ** Etag) const = 0 ;
NS_IMETHOD SetEtag(const char* i_Etag) = 0 ;
NS_IMETHOD GetExpires(PRIntervalTime * iTime) const = 0 ;
NS_IMETHOD SetExpires(const PRIntervalTime i_Time) = 0 ;
NS_IMETHOD GetFilename(char ** Filename) const = 0 ;
NS_IMETHOD SetFilename(const char* i_Filename) = 0 ;
NS_IMETHOD GetIsCompleted(PRBool * bComplete) const = 0 ;
NS_IMETHOD SetIsCompleted(PRBool bComplete) = 0 ;
NS_IMETHOD GetLastAccessed(PRIntervalTime * iTime) const = 0 ;
NS_IMETHOD SetLastModified(const PRIntervalTime i_Time) = 0 ;
NS_IMETHOD GetLastModified(PRIntervalTime * iTime) const = 0 ;
NS_IMETHOD GetModuleIndex(PRInt16 * m_index) const = 0 ;
NS_IMETHOD SetModuleIndex(const PRUint16 m_index) = 0 ;
NS_IMETHOD GetPageServicesURL(char ** o_url) const = 0 ;
NS_IMETHOD SetPageServicesURL(const char* i_Url) = 0 ;
NS_IMETHOD GetPostData(char ** pData) const = 0 ;
NS_IMETHOD SetPostData(const char* i_PostData, const PRUint32 i_Len) = 0 ;
NS_IMETHOD GetPostDataLen(PRUint32 * dLeng) const = 0 ;
NS_IMETHOD GetSize(PRUint32 * pSize) const = 0 ;
NS_IMETHOD SetSize(const PRUint32 i_Size) = 0 ;
NS_IMETHOD GetState(PRUint32 * pState) const = 0 ;
NS_IMETHOD SetState(const PRUint32 i_State) = 0 ;
NS_IMETHOD GetStream(nsStream ** pStream) const = 0 ;
// NS_IMETHOD MakeStream(void) = 0 ;
NS_IMETHOD Hits(PRUint32 * pHits) const = 0 ;
NS_IMETHOD IsExpired(PRBool * bGet) const = 0 ;
NS_IMETHOD IsPartial(PRBool * bGet) const = 0;
NS_IMETHOD Read(char* o_Destination, PRUint32 i_Len, PRUint32 * pLeng) = 0 ;
NS_IMETHOD Reset(void) = 0 ;
NS_IMETHOD Write(const char* i_buffer, const PRUint32 i_length,
PRUint32 * oLeng) = 0 ;
/* Read and write info about this cache object */
NS_IMETHOD GetInfo(void** o_info)=0 ;
NS_IMETHOD SetInfo(void* i_info /*, PRUint32 len */)=0;
NS_IMETHOD GetInfoSize(PRUint32* o_size)=0 ;
} ;
#endif // _NSICACHEOBJECT_H_

View File

@@ -1,90 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* nsICachePref. A class to separate the preference related code to
* one place. This is an incomplete implementation, I need to access
* the libprefs directly, but that would add another dependency. And
* libpref comes with a JS dependency... so holding this off for the
* moment.
*
* -Gagan Saksena 09/15/98
*/
#ifndef nsICachePref_h__
#define nsICachePref_h__
#include "nsISupports.h"
#include "prtypes.h"
#include "prlog.h"
// {7C3ED031-45E4-11d3-9B7F-0004ACB74CEC}
#define NS_ICACHEPREF_IID \
{ 0x7c3ed031, 0x45e4, 0x11d3, \
{ 0x9b, 0x7f, 0x0, 0x4, 0xac, 0xb7, 0x4c, 0xec } };
// myCachePrefCID {99E9C911-46D9-11d3-87EF-000629D01344}
#define NS_CACHEPREF_CID \
{ 0x99e9c911, 0x46d9, 0x11d3, \
{ 0x87, 0xef, 0x0, 0x6, 0x29, 0xd0, 0x13, 0x44}} ;
class nsICachePref : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR (NS_ICACHEPREF_IID);
// Was "static nsCachePref* GetInstance(void)"
// Do I need this GetInstance??????
// NS_IMETHOD GetInstance(nsICachePref** o_pICachePref ) = 0;
enum Refresh
{
ONCE,
ALWAYS,
NEVER
};
NS_IMETHOD GetBkgSleepTime (PRUint32* o_time) = 0;
NS_IMETHOD GetDiskCacheDBFilename (char** o_name) = 0; /* like Fat.db */
NS_IMETHOD GetDiskCacheFolder (char** o_folder) = 0; /* Cache dir */
NS_IMETHOD GetDiskCacheSSL (PRBool* o_bSet) = 0;
NS_IMETHOD SetDiskCacheSSL (PRBool i_bSet) = 0;
NS_IMETHOD GetDiskCacheSize (PRUint32* o_size) = 0;
NS_IMETHOD SetDiskCacheSize (const PRUint32 i_size) = 0;
NS_IMETHOD GetMemCacheSize (PRUint32 * o_size) = 0;
NS_IMETHOD SetMemCacheSize (const PRUint32 i_size) = 0;
NS_IMETHOD GetFrequency (nsICachePref::Refresh* o_frequency) = 0;
/* Revalidating in background, makes IMS calls in the bkg thread to
update cache entries. TODO, this should be at a bigger time period
than the cache cleanup routine */
NS_IMETHOD RevalidateInBkg (PRBool* i_bRevalidateInBkg) = 0;
/* Setup all prefs */
NS_IMETHOD SetupPrefs(const char* i_Pref) = 0;
};
#endif // nsICachePref_h__

View File

@@ -16,12 +16,17 @@
* Reserved.
*/
#include "nsINetDataCacheRecord.idl"
#include "nsrootidl.idl"
#include "nsISupports.idl"
interface nsIFileSpec;
interface nsIURI;
interface nsIObserver;
interface nsIChannel;
interface nsINetDataCache;
interface nsINetDataCacheRecord;
interface nsILoadGroup;
interface nsIStreamListener;
/**
* The nsICachedNetData interface represents a single entry in a database that
@@ -42,94 +47,155 @@ interface nsIObserver;
* @See nsINetDataCacheManager
*/
[scriptable, uuid(6aeb2a40-6d43-11d3-90c8-000064657374)]
interface nsICachedNetData : nsINetDataCacheRecord
interface nsICachedNetData : nsISupports
{
/**
* The URI that was provided as an argument to the call to
* String form of the URI provided as an argument to the call to
* nsINetDataCacheManager::GetCachedNetData() that created this record.
*/
readonly attribute nsIURI uri;
readonly attribute string uriSpec;
/**
* Getter for the opaque secondary database key that was provided as an
* argument to the call to nsINetDataCacheManager::GetCachedNetData() that
* created this record.
* Getter for the opaque secondary database key provided as an argument to
* the call to nsINetDataCacheManager::GetCachedNetData() that created this
* record.
*/
void getSecondaryKey(out unsigned long length,
[retval, size_is(length)] out string secondaryKey);
/**
* This flag may be set by a protocol handler to indicate that it supports
* partial fetching of data. In that case, the cache manager may truncate
* the entry's content to accommodate data for other cache entries rather
* than deleting it wholesale.
* partial fetching of data. In that case, the cache manager is permitted
* to truncate the entry's content to accommodate incoming data for other
* cache entries rather than deleting it wholesale.
*/
attribute boolean allowPartial;
/**
* This flag indicates that the write stream supplying content data for the
* cache did not complete normally, so the content may be truncated.
* cache did not complete normally and, therefore, the content may be
* truncated.
*/
readonly attribute boolean partial;
/**
* This flag can be set and cleared by a protocol handler so as to avoid
* race conditions in which the handler issues two identical network
* requests to fill the same cache entry.
* This flag can be set and cleared by a protocol handler as a form of
* self-notification, so as to avoid race conditions in which a protocol
* handler issues two identical network requests to fill the same cache
* entry. The cache manager itself largely ignores this flag.
*/
attribute boolean updateInProgress;
/**
* Date/time that the document was last stored on the origin server, as
* supplied by the protocol handler. If the protocol can't supply a
* last-modified time, this attribute should remain unset. This value
* is used as input to the cache replacement policy.
* supplied by the protocol handler. This value is used as input to the
* cache replacement policy, i.e. it is not used for validation. If the
* protocol can't supply a last-modified time, this attribute should remain
* unset. When unset, the value of this attribute is zero.
*
* FIXME: Should use nsIDateTime interface, once it's created
* instead of PRTime, for improved scriptability ?
* instead of PRTime, for improved scriptability ?
*/
readonly attribute PRTime lastModifiedTime;
attribute PRTime lastModifiedTime;
/**
* Date/time of expiration for this record, supplied by the protocol
* handler, at which point the content is *likely* to be stale. This
* heuristic date does not necessarily correspond to the HTTP Expires
* header, as it does not determine when cached network data must be
* validated with the origin server, but only serves as a hint to the cache
* replacement policy.
* Supplied by the protocol handler, the expirationTime attribute specifies
* the time until which the document is guaranteed fresh, i.e. the document
* does not have to be validated with the server and, therefore, any data
* in cache is definitely usable. The value of this attribute serves as a
* hint to the cache replacement policy. Only one of either staleTime or
* expirationTime may be set for a single cache record. When unset, the
* value of this attribute is zero.
*/
readonly attribute PRTime expirationTime;
attribute PRTime expirationTime;
/**
* Date/time of last access (retrieval) of the data in this record.
* Date/time supplied by the protocol handler, at which point the content
* is *likely* to be stale, i.e. the data in the cache may be out-of-date
* with respect to the data on the server. This heuristic date does not
* necessarily correspond to the HTTP Expires header, as it does not
* determine when cached network data must be validated with the origin
* server, but only serves as a hint to the cache replacement policy. Only
* one of either staleTime or expirationTime may be set for a single cache
* record. When unset, the value of this attribute is zero.
*/
readonly attribute PRTime lastRetrievalTime;
attribute PRTime staleTime;
/**
* Number of times an output stream has been created for this cache entry
* since it was first stored.
* Date/time of last access of the data in this cache record, as determined
* by the cache manager.
*/
readonly attribute PRUint16 numberRetrievals;
readonly attribute PRTime lastAccessTime;
/**
* If the underlying cache database is persistent, flush this entry's data
* to the database and the underlying nsINetDataCacheRecord instance.
* Number of times this record has been accessed since it was first stored.
*/
readonly attribute PRUint16 numberAccesses;
/**
* Accessors for opaque protocol-specific meta-data which can be updated by
* the protocol handler for each cache entry, independently of the content
* data.
*/
void getProtocolPrivate(out PRUint32 length, [size_is(length), retval] out string data);
void setProtocolPrivate(in PRUint32 length, [size_is(length)] in string data);
/**
* As a getter, return the number of content bytes stored in the cache,
* i.e. via the nsIChannel streaming APIs. This may be less than the
* complete content length if a partial cache fill occurred. The cached
* content can be truncated by setting the value of this attribute. The
* value of the attribute represents a logical, not a physical, length. If
* compression has been used, the content may consume less storage than
* indicated by this attribute.
*
* When this attribute is set to zero the associated cache disk file, if
* any, should be deleted.
*/
attribute PRUint32 storedContentLength;
/**
* Notify any observers associated with this cache entry of the deletion
* request. If all observers drop their reference to the cache entry,
* proceed to delete the underlying cache database record and associated
* content storage.
*/
void delete();
/**
* Flush any changes in this entry's data to the cache database. This
* method will automatically be called when the last reference to the cache
* is dropped, but it can also be called explicitly for a synchronous
* effect.
*/
void commit();
/**
* Add an observer for this cache record. When the cache wants to delete
* or truncate a record, so as to make space for another cache entry's
* content data, it will call <code>aObserver</code>'s Observe() method,
* passing the nsICachedNetData instance as the <code>aSubject</code>
* argument and "Eviction Notice" as the <code>aTopic</code> argument. If
* the observer does not wish to inhibit the deletion, it should Release()
* any references it has to the cache record.
* Parent container cache for this entry.
*/
void addObserver(in nsIObserver aObserver);
readonly attribute nsINetDataCache cache;
/**
* Delete an observer that was added by the AddObserver() method.
* Create a channel for reading or writing a stream of content into the
* entry. It is expected that many of the nsIChannel methods return
* NS_NOT_IMPLEMENTED, including:
*
* + GetURI()
* + GetContentType()
* + GetContentLength()
*
* Though nsIChannel provides for both async and synchronous I/O APIs, both
* may not be implemented. Only AsyncRead() and OpenOutputStream() is
* required.
*/
void removeObserver(in nsIObserver aObserver);
nsIChannel newChannel(in nsILoadGroup loadGroup);
/**
* This method can be used by a caching protocol handler to store data in
* the cache by forking an asynchronous read stream so that it is
* simultaneously sent to a requester and written into the cache. This
* method implicitly sets the updateInProgress flag, if it has not already
* been set.
*/
nsIStreamListener interceptAsyncRead(in nsIStreamListener aOriginalListener);
};

View File

@@ -24,10 +24,12 @@ interface nsISimpleEnumerator;
interface nsIFileSpec;
/**
* The nsINetDataCache defines a network-data cache, used to cache the
* responses to network retrieval commands. This interface, along with
* nsINetDataCacheRecord, is implemented by the memory cache, the disk cache
* and, optionally, by some extension caches.
* The nsINetDataCache defines the low-level API for a network-data
* cache, used to cache the responses to network retrieval commands.
* This interface, along with nsINetDataCacheRecord, is implemented by
* the memory cache, the file cache and, optionally, by some extension
* caches. This interface is essentially a pseudo-private API for the
* cache manager. Other clients should never use this interface.
*
* Each cache entry may contain both content, e.g. GIF image data, and
* associated metadata, e.g. HTTP headers. Each entry is indexed by two
@@ -36,7 +38,7 @@ interface nsIFileSpec;
*
* The nsINetDataCache interface is agnostic as to where the data is
* stored and whether the storage is volatile or persistent. The
* memory cache, the disk cache and any extension caches must all
* memory cache, any disk caches and any extension caches must all
* implement this interface.
*
*/
@@ -71,11 +73,22 @@ interface nsINetDataCache : nsISupports
*/
attribute boolean enabled;
/**
* Constants for flags attribute, below
*/
// Used for extension caches, e.g. a CD-ROM cache
const long READ_ONLY = 1 << 0;
// One of these bits must be set
const long MEMORY_CACHE = 1 << 1;
const long FLAT_FILE_CACHE = 1 << 2;
const long FILE_PER_URL_CACHE = 1 << 3;
/**
* This attribute will be false for the memory cache and the disk cache,
* but will be true for all other cache modules.
* See constants defined above.
*/
readonly attribute boolean readOnly;
readonly attribute PRUint32 flags;
/**
* Total number of URI entries stored in the cache.
@@ -100,12 +113,9 @@ interface nsINetDataCache : nsISupports
attribute nsINetDataCache nextCache;
/**
* Set the maximum permitted size of the cache, in kB. Setting the
* capacity lower than the current amount of space currently in use may
* cause cache entries to be evicted from the cache to accomodate the
* requested capacity.
* The maximum permitted size of the cache, in kB.
*/
attribute PRUint32 capacity;
readonly attribute PRUint32 capacity;
/**
* An estimate of the amount of storage occupied by the cache, in kB.
@@ -129,6 +139,6 @@ interface nsINetDataCache : nsISupports
// ProgID prefix for Components that implement this interface
#define NS_NETWORK_CACHE_PROGID "component://netscape/network/cache"
#define NS_NETWORK_MEMORY_CACHE_PROGID NS_NETWORK_CACHE_PROGID "?name=memory-cache"
#define NS_NETWORK_PERSISTENT_CACHE_PROGID NS_NETWORK_CACHE_PROGID "?name=persistent-cache"
#define NS_NETWORK_FLAT_CACHE_PROGID NS_NETWORK_CACHE_PROGID "?name=flat-cache"
#define NS_NETWORK_FILE_CACHE_PROGID NS_NETWORK_CACHE_PROGID "?name=file-cache"
%}

View File

@@ -48,31 +48,43 @@ interface nsINetDataCacheManager : nsISupports
* Flag for the GetCachedNetData() method: If set, the memory cache is
* neither searched nor will any data be stored into it. This might be
* appropriate, for example, with images, because they have their own
* memory cache for storing *decoded* images.
* cache for storing *decoded* images.
*/
const unsigned long BYPASS_MEMORY_CACHE = 1 << 0;
/**
* Flag for the GetCachedNetData() method: If set, the disk cache is
* neither searched nor will any be data stored into it. No extension
* caches be searched either. This might be used to avoid leaving
* persistent records of secure data.
* Flag for the GetCachedNetData() method: If set, the disk cache
* is neither searched nor will any be data stored into it.
* However, read-only extension caches may be searched. This
* might be used to avoid leaving persistent records of secure
* data.
*/
const unsigned long BYPASS_PERSISTENT_CACHE = 1 << 1;
/**
* Flag for the GetCachedNetData() method: If set, any stream
* content is stored in the cache as a single disk file. Content
* will not be cached in the memory cache nor is it cached in a
* flat-file cache database. This is used to implement the jar
* protocol handler and to provide the stream-as-file semantics
* required by the classic bowser plugin API.
*/
const unsigned long CACHE_AS_FILE = 1 << 2;
/**
* Fetch the cache entry record for the given URI. If one does not exist,
* create a new, empty record. The normal search order for caches is:
* + Memory cache
* + Disk cache
* + File cache (stream-as-file cache)
* + All extension caches
*
* When writing, data is typically stored in both the memory cache and the
* disk. Both the search order and this write policy can be modified by
* disk cache. Both the search order and this write policy can be modified by
* setting one or more of the flag argument bits, as defined above.
*
* The optionally-NULL secondaryKey argument can be used for form
* post data in the case of HTTP.
* The optionally-NULL secondaryKey argument can be used, e.g. for form
* post data or for HTTP headers in the case of HTTP.
*/
nsICachedNetData getCachedNetData(in nsIURI uri,
[size_is(secondaryKeyLength)] in string secondaryKey,
@@ -106,20 +118,11 @@ interface nsINetDataCacheManager : nsISupports
/*
* Enumerate all the loaded nsINetDataCache-implementing cache modules.
* The first module enumerated will be the memory cache, the second will be
* the disk cache, followed by all the extension caches, in search order.
* the disk cache, then the file cache, followed by all the extension
* caches, in search order.
*/
nsISimpleEnumerator newCacheModuleIterator();
/**
* Retrieve an interface pointer to the distinguished memory cache.
*/
readonly attribute nsINetDataCache memoryCache;
/**
* Retrieve an interface pointer to the distinguished disk cache.
*/
readonly attribute nsINetDataDiskCache diskCache;
/**
* Remove all entries from all writable caches. This could be used, for
* example, after a guest ends a browser session. This is equivalent to
@@ -130,9 +133,20 @@ interface nsINetDataCacheManager : nsISupports
void RemoveAll();
/**
* Return the number of times that GetCachedNetData() located an
* existing cache entry divided by the number of times
* GetCachedNetData was called.
* The disk cache is made up of the file cache (for stream-as-file
* requests) and a (possibly independent) persistent cache that handles all
* other cache requests. This attribute sets/gets the combined capacity of
* these caches, measured in KBytes. Setting the capacity lower than the
* current amount of space currently in use may cause cache entries to be
* evicted from the cache to accomodate the requested capacity.
*/
readonly attribute double hitRatio;
attribute PRUint32 diskCacheCapacity;
/**
* This attribute sets/gets the capacity of the memory cache, measured in
* KBytes. Setting the capacity lower than the current amount of space
* currently in use may cause cache entries to be evicted from the cache to
* accomodate the requested capacity.
*/
attribute PRUint32 memCacheCapacity;
};

View File

@@ -21,14 +21,16 @@
interface nsIFileSpec;
interface nsIChannel;
interface nsINetDataCache;
/**
* The nsINetDataCacheRecord represents a single entry in a database that
* caches data retrieved from the network. On top of this low-level interface
* to the raw record data, the cache manager implements a higher-level record
* interface, nsICachedNetData. Each instance of nsINetDataCacheRecord is
* associated with a parent database, an instance of the nsINetDataCache
* interface.
* (internally) associated with a parent database, an instance of the
* nsINetDataCache interface. This interface is essentially a pseudo-private
* API for the cache manager. Other clients should never use this interface.
*
* Each cache record may contain both content and metadata. The content may
* be, for example, GIF image data or HTML, and it is accessed through
@@ -91,24 +93,18 @@ interface nsINetDataCacheRecord : nsISupports
attribute PRUint32 storedContentLength;
/**
* Delete this cache entry and its associated content. If there are any
* outstanding nsIChannel instances associated with this cache record,
* an error is returned and deletion is not performed.
* Delete this cache entry and its associated content.
*/
void delete();
/**
* Create a channel for reading or writing a stream of content into the
* entry. It is expected that many of the nsIChannel methods return
* NS_NOT_IMPLEMENTED:
* entry. However, many of the nsIChannel methods may return
* NS_NOT_IMPLEMENTED, including:
*
* + GetURI()
* + GetContentType()
* + GetContentLength()
*
* Though nsIChannel provides for both async and synchronous I/O APIs, both
* need not be implemented. Only AsyncRead() and one of AsyncWrite() or
* OpenOutputStream() is required.
*/
nsIChannel newChannel(in nsILoadGroup loadGroup);

View File

@@ -0,0 +1,106 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Scott Furman, fur@netscape.com
*/
#include "nsrootidl.idl"
#include "nsISupports.idl"
interface nsIFileSpec;
interface nsIStreamAsFileObserver;
/**
* In addition to enhancing effective network response time via caching, the
* cache manager serves a second purpose by providing the stream-as-file
* service required by traditional browser plugins and the jar: protocol
* handler. The interface below provides a means for a client to determine the
* filename associated with a stream and to detect modification/deletion of
* that file.
*/
[scriptable, uuid(0eedbbf0-92d9-11d3-90d3-0040056a906e)]
interface nsIStreamAsFile : nsISupports
{
/**
* Filename containing stream-as-file
*/
readonly attribute nsIFileSpec fileSpec;
/**
* Add an observer for this cache record. When the cache wants to delete
* or truncate a record, so as to make space for another cache entry's
* content data, it will call <code>aObserver</code>'s Observe() method,
* passing the nsIStreamAsFile instance as the <code>aSubject</code>
* argument and an appropriate message. If the observer does not wish to
* inhibit deletion/truncation, it should Release() any references it has to the
* cache record.
*
* @See nsIStreamAsFileObserver
*/
void addObserver(in nsIStreamAsFileObserver aObserver);
/**
* Delete an observer that was added by the AddObserver() method.
*/
void removeObserver(in nsIStreamAsFileObserver aObserver);
};
/**
* This interface can be implemented by a client to receive notifications of
* either modification or deletion of a file created by the cache manager using
* the stream-as-file semantics.
*/
[scriptable, uuid(a26e27c0-92da-11d3-90d3-0040056a906e)]
interface nsIStreamAsFileObserver : nsISupports
{
/**
* Flag bits for argument to Observe() method.
*/
const long NOTIFY_AVAILABLE = 1 << 0; // Stream-as-file now available for reading
const long NOTIFY_ERROR = 1 << 1; // Error while loading stream / creating file
const long REQUEST_DELETION = 1 << 2; // Cache manager wishes to delete/truncate file
const long INVALIDATE = 1 << 3; // File is out-of-date
// Convenience value
const long MAKE_UNAVAILABLE = REQUEST_DELETION | INVALIDATE;
/**
* Receive either a notification or a request concerning a file that has
* been opened using stream-as-file. The aMessage and aError arguments
* have varying values depending on the nature of the notification.
* aMessage is set to NOTIFY_AVAILABLE when a complete stream has been read
* and stored on disk in a file. At that point, and no sooner, may the
* filename attribute of the associated nsIStreamAsFile be accessed via the
* associated nsIStreamAsFile interface. If the aMessage argument is
* NOTIFY_ERROR, the aError argument contains the relevant error code. If
* the aMessage argument is either REQUEST_DELETION or REQUEST_TRUNCATION,
* the callee should immediately Release() all references to the
* nsIStreamAsFile (and any references to its associated nsICachedNetData
* instances), unless it wishes to inhibit the requested file modification.
* If the aMessage argument is INVALIDATE, the cache manager is replacing
* the file with a more recent version. If a client wants to continue
* using the (now out-of-date) file, it must delete it when it has finished,
* as the cache manager will effectively relinquished ownership of the
* file.
*/
void ObserveStreamAsFile(in nsIStreamAsFile aStreamAsFile,
in PRUint32 aMessage,
in nsresult aError);
};