]>
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 { | |
6d68a230 | 11 | Ipc::Mem::PageId page; ///< shared memory page with entry 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 | ||
96a7de88 DK |
23 | /// whether e should be kept in local RAM for possible future caching |
24 | bool keepInLocalMemory(const StoreEntry &e) const; | |
25 | ||
4475555f AR |
26 | /// copy non-shared entry data of the being-cached entry to our cache |
27 | void write(StoreEntry &e); | |
28 | ||
29 | /// all data has been received; there will be no more write() calls | |
30 | void completeWriting(StoreEntry &e); | |
31 | ||
ce49546e AR |
32 | /// remove from the cache |
33 | void unlink(StoreEntry &e); | |
34 | ||
35 | /// called when the entry is about to forget its association with mem cache | |
4475555f | 36 | void disconnect(MemObject &mem_obj); |
ce49546e | 37 | |
9487bae9 AR |
38 | /* Store API */ |
39 | virtual int callback(); | |
40 | virtual StoreEntry * get(const cache_key *); | |
41 | virtual void get(String const key , STOREGETCLIENT callback, void *cbdata); | |
42 | virtual void init(); | |
43 | virtual uint64_t maxSize() const; | |
44 | virtual uint64_t minSize() const; | |
39c1e1d9 DK |
45 | virtual uint64_t currentSize() const; |
46 | virtual uint64_t currentCount() const; | |
af2fda07 | 47 | virtual int64_t maxObjectSize() const; |
93bc1434 | 48 | virtual void getStats(StoreInfoStats &stats) const; |
9487bae9 AR |
49 | virtual void stat(StoreEntry &) const; |
50 | virtual StoreSearch *search(String const url, HttpRequest *); | |
51 | virtual void reference(StoreEntry &); | |
54347cbd | 52 | virtual bool dereference(StoreEntry &, bool); |
9487bae9 | 53 | virtual void maintain(); |
4475555f | 54 | virtual bool anchorCollapsed(StoreEntry &collapsed, bool &inSync); |
ce49546e | 55 | virtual bool updateCollapsed(StoreEntry &collapsed); |
9487bae9 | 56 | |
68353d5a | 57 | static int64_t EntryLimit(); |
a4555399 | 58 | |
9487bae9 | 59 | protected: |
4475555f AR |
60 | bool shouldCache(const StoreEntry &e) const; |
61 | bool startCaching(StoreEntry &e); | |
9487bae9 | 62 | |
4475555f AR |
63 | void copyToShm(StoreEntry &e); |
64 | void copyToShmSlice(StoreEntry &e, Ipc::StoreMapAnchor &anchor); | |
06684a9b | 65 | bool copyFromShm(StoreEntry &e, const sfileno index, const Ipc::StoreMapAnchor &anchor); |
ce49546e AR |
66 | bool copyFromShmSlice(StoreEntry &e, const StoreIOBuffer &buf, bool eof); |
67 | ||
68 | void anchorEntry(StoreEntry &e, const sfileno index, const Ipc::StoreMapAnchor &anchor); | |
69 | bool updateCollapsedWith(StoreEntry &collapsed, const sfileno index, const Ipc::StoreMapAnchor &anchor); | |
06684a9b AR |
70 | |
71 | sfileno reserveSapForWriting(Ipc::Mem::PageId &page); | |
9487bae9 | 72 | |
7f6748c8 | 73 | // Ipc::StoreMapCleaner API |
10dc0fe6 | 74 | virtual void noteFreeMapSlice(const sfileno sliceId); |
7f6748c8 | 75 | |
9487bae9 | 76 | private: |
06684a9b AR |
77 | // TODO: move freeSlots into map |
78 | Ipc::Mem::Pointer<Ipc::Mem::PageStack> freeSlots; ///< unused map slot IDs | |
9487bae9 | 79 | MemStoreMap *map; ///< index of mem-cached entries |
06684a9b AR |
80 | |
81 | /// the last allocate slice for writing a store entry (during copyToShm) | |
82 | sfileno lastWritingSlice; | |
83 | ||
84 | /// temporary storage for slot and page ID pointers; for the waiting cache | |
85 | class SlotAndPage { | |
86 | public: | |
87 | SlotAndPage(): slot(NULL), page(NULL) {} | |
88 | bool operator !() const { return !slot && !page; } | |
89 | Ipc::Mem::PageId *slot; ///< local slot variable, waiting to be filled | |
90 | Ipc::Mem::PageId *page; ///< local page variable, waiting to be filled | |
91 | }; | |
92 | SlotAndPage waitingFor; ///< a cache for a single "hot" free slot and page | |
9487bae9 AR |
93 | }; |
94 | ||
95 | // Why use Store as a base? MemStore and SwapDir are both "caches". | |
96 | ||
97 | // Why not just use a SwapDir API? That would not help much because Store has | |
98 | // to check/update memory cache separately from the disk cache. And same API | |
99 | // would hurt because we can support synchronous get/put, unlike the disks. | |
100 | ||
101 | #endif /* SQUID_MEMSTORE_H */ |