1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is nsMemoryCacheDevice.h, released
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 2001
22 * the Initial Developer. All Rights Reserved.
25 * Gordon Sheridan, 20-February-2001
26 * Brian Ryner <bryner@brianryner.com>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #ifndef _nsMemoryCacheDevice_h_
43 #define _nsMemoryCacheDevice_h_
45 #include "nsCacheDevice.h"
47 #include "nsCacheEntry.h"
50 class nsMemoryCacheDeviceInfo
;
52 /******************************************************************************
54 ******************************************************************************/
55 class nsMemoryCacheDevice
: public nsCacheDevice
58 nsMemoryCacheDevice();
59 virtual ~nsMemoryCacheDevice();
61 virtual nsresult
Init();
62 virtual nsresult
Shutdown();
64 virtual const char * GetDeviceID(void);
66 virtual nsresult
BindEntry( nsCacheEntry
* entry
);
67 virtual nsCacheEntry
* FindEntry( nsCString
* key
, PRBool
*collision
);
68 virtual void DoomEntry( nsCacheEntry
* entry
);
69 virtual nsresult
DeactivateEntry( nsCacheEntry
* entry
);
71 virtual nsresult
OpenInputStreamForEntry(nsCacheEntry
* entry
,
72 nsCacheAccessMode mode
,
74 nsIInputStream
** result
);
76 virtual nsresult
OpenOutputStreamForEntry(nsCacheEntry
* entry
,
77 nsCacheAccessMode mode
,
79 nsIOutputStream
** result
);
81 virtual nsresult
GetFileForEntry( nsCacheEntry
* entry
,
84 virtual nsresult
OnDataSizeChange( nsCacheEntry
* entry
, PRInt32 deltaSize
);
86 virtual nsresult
Visit( nsICacheVisitor
* visitor
);
88 virtual nsresult
EvictEntries(const char * clientID
);
90 void SetCapacity(PRInt32 capacity
);
93 friend class nsMemoryCacheDeviceInfo
;
94 enum { DELETE_ENTRY
= PR_TRUE
,
95 DO_NOT_DELETE_ENTRY
= PR_FALSE
};
97 void AdjustMemoryLimits( PRInt32 softLimit
, PRInt32 hardLimit
);
98 void EvictEntry( nsCacheEntry
* entry
, PRBool deleteEntry
);
99 void EvictEntriesIfNecessary();
100 int EvictionList(nsCacheEntry
* entry
, PRInt32 deltaSize
);
103 void CheckEntryCount();
109 kQueueCount
= 24 // entries > 2^23 (8Mb) start in last queue
112 nsCacheEntryHashTable mMemCacheEntries
;
115 PRCList mEvictionList
[kQueueCount
];
116 PRInt32 mEvictionThreshold
;
122 PRInt32 mInactiveSize
;
125 PRInt32 mMaxEntryCount
;
127 // XXX what other stats do we want to keep?
131 /******************************************************************************
132 * nsMemoryCacheDeviceInfo - used to call nsIVisitor for about:cache
133 ******************************************************************************/
134 class nsMemoryCacheDeviceInfo
: public nsICacheDeviceInfo
{
137 NS_DECL_NSICACHEDEVICEINFO
139 nsMemoryCacheDeviceInfo(nsMemoryCacheDevice
* device
)
144 virtual ~nsMemoryCacheDeviceInfo() {}
147 nsMemoryCacheDevice
* mDevice
;
151 #endif // _nsMemoryCacheDevice_h_