2 * Copyright (C) 1996-2017 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_TRANSIENTS_H
10 #define SQUID_TRANSIENTS_H
12 #include "http/MethodType.h"
13 #include "ipc/mem/Page.h"
14 #include "ipc/mem/PageStack.h"
15 #include "ipc/StoreMap.h"
17 #include "store/Controlled.h"
20 // StoreEntry restoration info not already stored by Ipc::StoreMap
21 struct TransientsMapExtraItem
{
22 char url
[MAX_URL
+1]; ///< Request-URI; TODO: decrease MAX_URL by one
23 RequestFlags reqFlags
; ///< request flags
24 Http::MethodType reqMethod
; ///< request method; extensions are not supported
26 typedef Ipc::StoreMapItems
<TransientsMapExtraItem
> TransientsMapExtras
;
27 typedef Ipc::StoreMap TransientsMap
;
29 /// Keeps track of store entries being delivered to clients that arrived before
30 /// those entries were [fully] cached. This shared table is necessary to sync
31 /// the entry-writing worker with entry-reading worker(s).
32 class Transients
: public Store::Controlled
, public Ipc::StoreMapCleaner
36 virtual ~Transients();
38 /// return a local, previously collapsed entry
39 StoreEntry
*findCollapsed(const sfileno xitIndex
);
41 /// add an in-transit entry suitable for collapsing future requests
42 void startWriting(StoreEntry
*e
, const RequestFlags
&reqFlags
, const HttpRequestMethod
&reqMethod
);
44 /// called when the in-transit entry has been successfully cached
45 void completeWriting(const StoreEntry
&e
);
47 /// the calling entry writer no longer expects to cache this entry
48 void abandon(const StoreEntry
&e
);
50 /// whether an in-transit entry is now abandoned by its writer
51 bool abandoned(const StoreEntry
&e
) const;
53 /// number of entry readers some time ago
54 int readers(const StoreEntry
&e
) const;
56 /// the caller is done writing or reading this entry
57 void disconnect(MemObject
&mem_obj
);
60 virtual StoreEntry
*get(const cache_key
*) override
;
61 virtual void create() override
{}
62 virtual void init() override
;
63 virtual uint64_t maxSize() const override
;
64 virtual uint64_t minSize() const override
;
65 virtual uint64_t currentSize() const override
;
66 virtual uint64_t currentCount() const override
;
67 virtual int64_t maxObjectSize() const override
;
68 virtual void getStats(StoreInfoStats
&stats
) const override
;
69 virtual void stat(StoreEntry
&e
) const override
;
70 virtual void reference(StoreEntry
&e
) override
;
71 virtual bool dereference(StoreEntry
&e
) override
;
72 virtual void markForUnlink(StoreEntry
&e
) override
;
73 virtual void unlink(StoreEntry
&e
) override
;
74 virtual void maintain() override
;
75 virtual bool smpAware() const override
{ return true; }
77 static int64_t EntryLimit();
80 StoreEntry
*copyFromShm(const sfileno index
);
81 bool copyToShm(const StoreEntry
&e
, const sfileno index
, const RequestFlags
&reqFlags
, const HttpRequestMethod
&reqMethod
);
83 bool abandonedAt(const sfileno index
) const;
85 // Ipc::StoreMapCleaner API
86 virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId
) override
;
89 /// shared packed info indexed by Store keys, for creating new StoreEntries
92 /// shared packed info that standard StoreMap does not store for us
93 typedef TransientsMapExtras Extras
;
94 Ipc::Mem::Pointer
<Extras
> extras
;
96 typedef std::vector
<StoreEntry
*> Locals
;
97 /// local collapsed entries indexed by transient ID, for syncing old StoreEntries
101 // TODO: Why use Store as a base? We are not really a cache.
103 #endif /* SQUID_TRANSIENTS_H */