]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/MemStore.h
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_MEMSTORE_H
10 #define SQUID_MEMSTORE_H
12 #include "ipc/mem/Page.h"
13 #include "ipc/mem/PageStack.h"
14 #include "ipc/StoreMap.h"
17 // StoreEntry restoration info not already stored by Ipc::StoreMap
18 struct MemStoreMapExtraItem
{
19 Ipc::Mem::PageId page
; ///< shared memory page with entry slice content
21 typedef Ipc::StoreMapItems
<MemStoreMapExtraItem
> MemStoreMapExtras
;
22 typedef Ipc::StoreMap MemStoreMap
;
24 /// Stores HTTP entities in RAM. Current implementation uses shared memory.
25 /// Unlike a disk store (SwapDir), operations are synchronous (and fast).
26 class MemStore
: public Store
, public Ipc::StoreMapCleaner
32 /// whether e should be kept in local RAM for possible future caching
33 bool keepInLocalMemory(const StoreEntry
&e
) const;
35 /// copy non-shared entry data of the being-cached entry to our cache
36 void write(StoreEntry
&e
);
38 /// all data has been received; there will be no more write() calls
39 void completeWriting(StoreEntry
&e
);
41 /// remove from the cache
42 void unlink(StoreEntry
&e
);
44 /// called when the entry is about to forget its association with mem cache
45 void disconnect(StoreEntry
&e
);
48 virtual int callback();
49 virtual StoreEntry
* get(const cache_key
*);
50 virtual void get(String
const key
, STOREGETCLIENT callback
, void *cbdata
);
52 virtual uint64_t maxSize() const;
53 virtual uint64_t minSize() const;
54 virtual uint64_t currentSize() const;
55 virtual uint64_t currentCount() const;
56 virtual int64_t maxObjectSize() const;
57 virtual void getStats(StoreInfoStats
&stats
) const;
58 virtual void stat(StoreEntry
&) const;
59 virtual StoreSearch
*search(String
const url
, HttpRequest
*);
60 virtual void markForUnlink(StoreEntry
&e
);
61 virtual void reference(StoreEntry
&);
62 virtual bool dereference(StoreEntry
&, bool);
63 virtual void maintain();
64 virtual bool anchorCollapsed(StoreEntry
&collapsed
, bool &inSync
);
65 virtual bool updateCollapsed(StoreEntry
&collapsed
);
67 static int64_t EntryLimit();
70 bool shouldCache(StoreEntry
&e
) const;
71 bool startCaching(StoreEntry
&e
);
73 void copyToShm(StoreEntry
&e
);
74 void copyToShmSlice(StoreEntry
&e
, Ipc::StoreMapAnchor
&anchor
);
75 bool copyFromShm(StoreEntry
&e
, const sfileno index
, const Ipc::StoreMapAnchor
&anchor
);
76 bool copyFromShmSlice(StoreEntry
&e
, const StoreIOBuffer
&buf
, bool eof
);
78 void anchorEntry(StoreEntry
&e
, const sfileno index
, const Ipc::StoreMapAnchor
&anchor
);
79 bool updateCollapsedWith(StoreEntry
&collapsed
, const sfileno index
, const Ipc::StoreMapAnchor
&anchor
);
81 sfileno
reserveSapForWriting(Ipc::Mem::PageId
&page
);
83 // Ipc::StoreMapCleaner API
84 virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId
);
87 // TODO: move freeSlots into map
88 Ipc::Mem::Pointer
<Ipc::Mem::PageStack
> freeSlots
; ///< unused map slot IDs
89 MemStoreMap
*map
; ///< index of mem-cached entries
91 typedef MemStoreMapExtras Extras
;
92 Ipc::Mem::Pointer
<Extras
> extras
; ///< IDs of pages with slice data
94 /// the last allocate slice for writing a store entry (during copyToShm)
95 sfileno lastWritingSlice
;
97 /// temporary storage for slot and page ID pointers; for the waiting cache
101 SlotAndPage(): slot(NULL
), page(NULL
) {}
102 bool operator !() const { return !slot
&& !page
; }
103 Ipc::Mem::PageId
*slot
; ///< local slot variable, waiting to be filled
104 Ipc::Mem::PageId
*page
; ///< local page variable, waiting to be filled
106 SlotAndPage waitingFor
; ///< a cache for a single "hot" free slot and page
109 // Why use Store as a base? MemStore and SwapDir are both "caches".
111 // Why not just use a SwapDir API? That would not help much because Store has
112 // to check/update memory cache separately from the disk cache. And same API
113 // would hurt because we can support synchronous get/put, unlike the disks.
115 #endif /* SQUID_MEMSTORE_H */