]>
Commit | Line | Data |
---|---|---|
9487bae9 AR |
1 | #ifndef SQUID_MEMSTORE_H |
2 | #define SQUID_MEMSTORE_H | |
3 | ||
68353d5a | 4 | #include "ipc/mem/Page.h" |
06684a9b | 5 | #include "ipc/mem/PageStack.h" |
68353d5a | 6 | #include "ipc/StoreMap.h" |
9487bae9 | 7 | #include "Store.h" |
68353d5a DK |
8 | |
9 | // StoreEntry restoration info not already stored by Ipc::StoreMap | |
10 | struct MemStoreMapExtras { | |
06684a9b | 11 | Ipc::Mem::PageId page; ///< shared memory page with the slice content |
68353d5a DK |
12 | }; |
13 | typedef Ipc::StoreMapWithExtras<MemStoreMapExtras> MemStoreMap; | |
9487bae9 AR |
14 | |
15 | /// Stores HTTP entities in RAM. Current implementation uses shared memory. | |
16 | /// Unlike a disk store (SwapDir), operations are synchronous (and fast). | |
9199139f AR |
17 | class MemStore: public Store, public Ipc::StoreMapCleaner |
18 | { | |
9487bae9 AR |
19 | public: |
20 | MemStore(); | |
21 | virtual ~MemStore(); | |
22 | ||
23 | /// cache the entry or forget about it until the next considerKeeping call | |
24 | void considerKeeping(StoreEntry &e); | |
25 | ||
96a7de88 DK |
26 | /// whether e should be kept in local RAM for possible future caching |
27 | bool keepInLocalMemory(const StoreEntry &e) const; | |
28 | ||
9487bae9 AR |
29 | /* Store API */ |
30 | virtual int callback(); | |
31 | virtual StoreEntry * get(const cache_key *); | |
32 | virtual void get(String const key , STOREGETCLIENT callback, void *cbdata); | |
33 | virtual void init(); | |
34 | virtual uint64_t maxSize() const; | |
35 | virtual uint64_t minSize() const; | |
39c1e1d9 DK |
36 | virtual uint64_t currentSize() const; |
37 | virtual uint64_t currentCount() const; | |
af2fda07 | 38 | virtual int64_t maxObjectSize() const; |
93bc1434 | 39 | virtual void getStats(StoreInfoStats &stats) const; |
9487bae9 AR |
40 | virtual void stat(StoreEntry &) const; |
41 | virtual StoreSearch *search(String const url, HttpRequest *); | |
42 | virtual void reference(StoreEntry &); | |
54347cbd | 43 | virtual bool dereference(StoreEntry &, bool); |
9487bae9 | 44 | virtual void maintain(); |
9487bae9 | 45 | |
68353d5a | 46 | static int64_t EntryLimit(); |
a4555399 | 47 | |
9487bae9 | 48 | protected: |
9487bae9 AR |
49 | void keep(StoreEntry &e); |
50 | ||
06684a9b AR |
51 | bool copyToShm(StoreEntry &e, const sfileno index, Ipc::StoreMapAnchor &anchor); |
52 | bool copyToShmSlice(StoreEntry &e, const sfileno index, Ipc::StoreMapAnchor &anchor, int64_t &offset); | |
53 | bool copyFromShm(StoreEntry &e, const sfileno index, const Ipc::StoreMapAnchor &anchor); | |
54 | bool copyFromShmSlice(StoreEntry &e, StoreIOBuffer &buf, bool eof); | |
55 | ||
56 | sfileno reserveSapForWriting(Ipc::Mem::PageId &page); | |
9487bae9 | 57 | |
7f6748c8 | 58 | // Ipc::StoreMapCleaner API |
10dc0fe6 | 59 | virtual void noteFreeMapSlice(const sfileno sliceId); |
7f6748c8 | 60 | |
9487bae9 | 61 | private: |
06684a9b AR |
62 | // TODO: move freeSlots into map |
63 | Ipc::Mem::Pointer<Ipc::Mem::PageStack> freeSlots; ///< unused map slot IDs | |
9487bae9 | 64 | MemStoreMap *map; ///< index of mem-cached entries |
06684a9b AR |
65 | |
66 | /// the last allocate slice for writing a store entry (during copyToShm) | |
67 | sfileno lastWritingSlice; | |
68 | ||
69 | /// temporary storage for slot and page ID pointers; for the waiting cache | |
70 | class SlotAndPage { | |
71 | public: | |
72 | SlotAndPage(): slot(NULL), page(NULL) {} | |
73 | bool operator !() const { return !slot && !page; } | |
74 | Ipc::Mem::PageId *slot; ///< local slot variable, waiting to be filled | |
75 | Ipc::Mem::PageId *page; ///< local page variable, waiting to be filled | |
76 | }; | |
77 | SlotAndPage waitingFor; ///< a cache for a single "hot" free slot and page | |
9487bae9 AR |
78 | }; |
79 | ||
80 | // Why use Store as a base? MemStore and SwapDir are both "caches". | |
81 | ||
82 | // Why not just use a SwapDir API? That would not help much because Store has | |
83 | // to check/update memory cache separately from the disk cache. And same API | |
84 | // would hurt because we can support synchronous get/put, unlike the disks. | |
85 | ||
86 | #endif /* SQUID_MEMSTORE_H */ |