1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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 _nsDiskCacheEntry_h_
8 #define _nsDiskCacheEntry_h_
10 #include "nsDiskCacheMap.h"
12 #include "nsCacheEntry.h"
15 /******************************************************************************
17 *****************************************************************************/
18 struct nsDiskCacheEntry
{
19 uint32_t mHeaderVersion
; // useful for stand-alone metadata files
20 uint32_t mMetaLocation
; // for verification
22 uint32_t mLastFetched
;
23 uint32_t mLastModified
;
24 uint32_t mExpirationTime
;
26 uint32_t mKeySize
; // includes terminating null byte
27 uint32_t mMetaDataSize
; // includes terminating null byte
28 // followed by key data (mKeySize bytes)
29 // followed by meta data (mMetaDataSize bytes)
31 uint32_t Size() { return sizeof(nsDiskCacheEntry
) +
32 mKeySize
+ mMetaDataSize
;
35 char* Key() { return reinterpret_cast<char*const>(this) +
36 sizeof(nsDiskCacheEntry
);
40 { return Key() + mKeySize
; }
42 nsCacheEntry
* CreateCacheEntry(nsCacheDevice
* device
);
44 void Swap() // host to network (memory to disk)
46 #if defined(IS_LITTLE_ENDIAN)
47 mHeaderVersion
= htonl(mHeaderVersion
);
48 mMetaLocation
= htonl(mMetaLocation
);
49 mFetchCount
= htonl(mFetchCount
);
50 mLastFetched
= htonl(mLastFetched
);
51 mLastModified
= htonl(mLastModified
);
52 mExpirationTime
= htonl(mExpirationTime
);
53 mDataSize
= htonl(mDataSize
);
54 mKeySize
= htonl(mKeySize
);
55 mMetaDataSize
= htonl(mMetaDataSize
);
59 void Unswap() // network to host (disk to memory)
61 #if defined(IS_LITTLE_ENDIAN)
62 mHeaderVersion
= ntohl(mHeaderVersion
);
63 mMetaLocation
= ntohl(mMetaLocation
);
64 mFetchCount
= ntohl(mFetchCount
);
65 mLastFetched
= ntohl(mLastFetched
);
66 mLastModified
= ntohl(mLastModified
);
67 mExpirationTime
= ntohl(mExpirationTime
);
68 mDataSize
= ntohl(mDataSize
);
69 mKeySize
= ntohl(mKeySize
);
70 mMetaDataSize
= ntohl(mMetaDataSize
);
76 /******************************************************************************
77 * nsDiskCacheEntryInfo
78 *****************************************************************************/
79 class nsDiskCacheEntryInfo
: public nsICacheEntryInfo
{
82 NS_DECL_NSICACHEENTRYINFO
84 nsDiskCacheEntryInfo(const char * deviceID
, nsDiskCacheEntry
* diskEntry
)
86 , mDiskEntry(diskEntry
)
90 const char* Key() { return mDiskEntry
->Key(); }
93 virtual ~nsDiskCacheEntryInfo() {}
95 const char * mDeviceID
;
96 nsDiskCacheEntry
* mDiskEntry
;
100 #endif /* _nsDiskCacheEntry_h_ */