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_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"
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
25 typedef Ipc::StoreMapItems
<TransientsMapExtraItem
> TransientsMapExtras
;
26 typedef Ipc::StoreMap TransientsMap
;
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
35 virtual ~Transients();
37 /// return a local, previously collapsed entry
38 StoreEntry
*findCollapsed(const sfileno xitIndex
);
40 /// add an in-transit entry suitable for collapsing future requests
41 void startWriting(StoreEntry
*e
, const RequestFlags
&reqFlags
, const HttpRequestMethod
&reqMethod
);
43 /// called when the in-transit entry has been successfully cached
44 void completeWriting(const StoreEntry
&e
);
46 /// the calling entry writer no longer expects to cache this entry
47 void abandon(const StoreEntry
&e
);
49 /// whether an in-transit entry is now abandoned by its writer
50 bool abandoned(const StoreEntry
&e
) const;
52 /// number of entry readers some time ago
53 int readers(const StoreEntry
&e
) const;
55 /// the caller is done writing or reading this entry
56 void disconnect(MemObject
&mem_obj
);
59 virtual int callback();
60 virtual StoreEntry
* get(const cache_key
*);
61 virtual void get(String
const key
, STOREGETCLIENT callback
, void *cbdata
);
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();
76 static int64_t EntryLimit();
79 StoreEntry
*copyFromShm(const sfileno index
);
80 bool copyToShm(const StoreEntry
&e
, const sfileno index
, const RequestFlags
&reqFlags
, const HttpRequestMethod
&reqMethod
);
82 bool abandonedAt(const sfileno index
) const;
84 // Ipc::StoreMapCleaner API
85 virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId sliceId
);
88 /// shared packed info indexed by Store keys, for creating new StoreEntries
91 /// shared packed info that standard StoreMap does not store for us
92 typedef TransientsMapExtras Extras
;
93 Ipc::Mem::Pointer
<Extras
> extras
;
95 typedef std::vector
<StoreEntry
*> Locals
;
96 /// local collapsed entries indexed by transient ID, for syncing old StoreEntries
100 // TODO: Why use Store as a base? We are not really a cache.
102 #endif /* SQUID_TRANSIENTS_H */