1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim: set ts=8 sts=4 et sw=4 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef _nsMemoryCacheDevice_h_
8 #define _nsMemoryCacheDevice_h_
10 #include "nsCacheDevice.h"
12 #include "nsCacheEntry.h"
15 class nsMemoryCacheDeviceInfo
;
17 /******************************************************************************
19 ******************************************************************************/
20 class nsMemoryCacheDevice
: public nsCacheDevice
23 nsMemoryCacheDevice();
24 virtual ~nsMemoryCacheDevice();
26 virtual nsresult
Init();
27 virtual nsresult
Shutdown();
29 virtual const char * GetDeviceID(void);
31 virtual nsresult
BindEntry( nsCacheEntry
* entry
);
32 virtual nsCacheEntry
* FindEntry( nsCString
* key
, bool *collision
);
33 virtual void DoomEntry( nsCacheEntry
* entry
);
34 virtual nsresult
DeactivateEntry( nsCacheEntry
* entry
);
36 virtual nsresult
OpenInputStreamForEntry(nsCacheEntry
* entry
,
37 nsCacheAccessMode mode
,
39 nsIInputStream
** result
);
41 virtual nsresult
OpenOutputStreamForEntry(nsCacheEntry
* entry
,
42 nsCacheAccessMode mode
,
44 nsIOutputStream
** result
);
46 virtual nsresult
GetFileForEntry( nsCacheEntry
* entry
,
49 virtual nsresult
OnDataSizeChange( nsCacheEntry
* entry
, int32_t deltaSize
);
51 virtual nsresult
Visit( nsICacheVisitor
* visitor
);
53 virtual nsresult
EvictEntries(const char * clientID
);
54 nsresult
EvictPrivateEntries();
56 void SetCapacity(int32_t capacity
);
57 void SetMaxEntrySize(int32_t maxSizeInKilobytes
);
59 bool EntryIsTooBig(int64_t entrySize
);
64 friend class nsMemoryCacheDeviceInfo
;
65 enum { DELETE_ENTRY
= true,
66 DO_NOT_DELETE_ENTRY
= false };
68 void AdjustMemoryLimits( int32_t softLimit
, int32_t hardLimit
);
69 void EvictEntry( nsCacheEntry
* entry
, bool deleteEntry
);
70 void EvictEntriesIfNecessary();
71 int EvictionList(nsCacheEntry
* entry
, int32_t deltaSize
);
73 typedef bool (*EvictionMatcherFn
)(nsCacheEntry
* entry
, void* args
);
74 nsresult
DoEvictEntries(EvictionMatcherFn matchFn
, void* args
);
77 void CheckEntryCount();
83 kQueueCount
= 24 // entries > 2^23 (8Mb) start in last queue
86 nsCacheEntryHashTable mMemCacheEntries
;
89 PRCList mEvictionList
[kQueueCount
];
95 int32_t mInactiveSize
;
98 int32_t mMaxEntryCount
;
99 int32_t mMaxEntrySize
; // internal unit is bytes
101 // XXX what other stats do we want to keep?
105 /******************************************************************************
106 * nsMemoryCacheDeviceInfo - used to call nsIVisitor for about:cache
107 ******************************************************************************/
108 class nsMemoryCacheDeviceInfo
: public nsICacheDeviceInfo
{
111 NS_DECL_NSICACHEDEVICEINFO
113 explicit nsMemoryCacheDeviceInfo(nsMemoryCacheDevice
* device
)
119 virtual ~nsMemoryCacheDeviceInfo() {}
120 nsMemoryCacheDevice
* mDevice
;
124 #endif // _nsMemoryCacheDevice_h_