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