]> git.ipfire.org Git - thirdparty/squid.git/blob - src/Transients.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / Transients.h
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 #ifndef SQUID_TRANSIENTS_H
10 #define SQUID_TRANSIENTS_H
11
12 #include "http/MethodType.h"
13 #include "ipc/mem/Page.h"
14 #include "ipc/mem/PageStack.h"
15 #include "ipc/StoreMap.h"
16 #include "Store.h"
17 #include <vector>
18
19 // StoreEntry restoration info not already stored by Ipc::StoreMap
20 struct TransientsMapExtraItem {
21 char url[MAX_URL+1]; ///< Request-URI; TODO: decrease MAX_URL by one
22 RequestFlags reqFlags; ///< request flags
23 Http::MethodType reqMethod; ///< request method; extensions are not supported
24 };
25 typedef Ipc::StoreMapItems<TransientsMapExtraItem> TransientsMapExtras;
26 typedef Ipc::StoreMap TransientsMap;
27
28 /// Keeps track of store entries being delivered to clients that arrived before
29 /// those entries were [fully] cached. This shared table is necessary to sync
30 /// the entry-writing worker with entry-reading worker(s).
31 class Transients: public Store, public Ipc::StoreMapCleaner
32 {
33 public:
34 Transients();
35 virtual ~Transients();
36
37 /// return a local, previously collapsed entry
38 StoreEntry *findCollapsed(const sfileno xitIndex);
39
40 /// add an in-transit entry suitable for collapsing future requests
41 void startWriting(StoreEntry *e, const RequestFlags &reqFlags, const HttpRequestMethod &reqMethod);
42
43 /// called when the in-transit entry has been successfully cached
44 void completeWriting(const StoreEntry &e);
45
46 /// the calling entry writer no longer expects to cache this entry
47 void abandon(const StoreEntry &e);
48
49 /// whether an in-transit entry is now abandoned by its writer
50 bool abandoned(const StoreEntry &e) const;
51
52 /// number of entry readers some time ago
53 int readers(const StoreEntry &e) const;
54
55 /// the caller is done writing or reading this entry
56 void disconnect(MemObject &mem_obj);
57
58 /* Store API */
59 virtual int callback();
60 virtual StoreEntry * get(const cache_key *);
61 virtual void get(String const key , STOREGETCLIENT callback, void *cbdata);
62 virtual void init();
63 virtual uint64_t maxSize() const;
64 virtual uint64_t minSize() const;
65 virtual uint64_t currentSize() const;
66 virtual uint64_t currentCount() const;
67 virtual int64_t maxObjectSize() const;
68 virtual void getStats(StoreInfoStats &stats) const;
69 virtual void stat(StoreEntry &) const;
70 virtual StoreSearch *search(String const url, HttpRequest *);
71 virtual void reference(StoreEntry &);
72 virtual bool dereference(StoreEntry &, bool);
73 virtual void markForUnlink(StoreEntry &e);
74 virtual void maintain();
75
76 static int64_t EntryLimit();
77
78 protected:
79 StoreEntry *copyFromShm(const sfileno index);
80 bool copyToShm(const StoreEntry &e, const sfileno index, const RequestFlags &reqFlags, const HttpRequestMethod &reqMethod);
81
82 bool abandonedAt(const sfileno index) const;
83
84 // Ipc::StoreMapCleaner API
85 virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId);
86
87 private:
88 /// shared packed info indexed by Store keys, for creating new StoreEntries
89 TransientsMap *map;
90
91 /// shared packed info that standard StoreMap does not store for us
92 typedef TransientsMapExtras Extras;
93 Ipc::Mem::Pointer<Extras> extras;
94
95 typedef std::vector<StoreEntry*> Locals;
96 /// local collapsed entries indexed by transient ID, for syncing old StoreEntries
97 Locals *locals;
98 };
99
100 // TODO: Why use Store as a base? We are not really a cache.
101
102 #endif /* SQUID_TRANSIENTS_H */
103