3 * $Id: Store.h,v 1.42 2008/01/20 08:54:28 amosjeffries Exp $
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
41 #include "StoreIOBuffer.h"
46 #include "RemovalPolicy.h"
49 #include "ESIElement.h"
60 class StoreEntry
: public hash_link
64 static DeferredRead::DeferrableRead DeferReader
;
65 bool checkDeferRead(int fd
) const;
67 virtual const char *getMD5Text() const;
69 StoreEntry(const char *url
, const char *log_url
);
70 virtual ~StoreEntry(){}
72 virtual HttpReply
const *getReply() const;
73 virtual void write (StoreIOBuffer
);
74 virtual _SQUID_INLINE_
bool isEmpty() const;
75 virtual bool isAccepting() const;
76 virtual size_t bytesWanted(Range
<size_t> const) const;
77 virtual void complete();
78 virtual store_client_t
storeClientType() const;
79 virtual char const *getSerialisedMetaData();
80 virtual void replaceHttpReply(HttpReply
*);
81 virtual bool swapoutPossible();
82 virtual void trimMemory();
90 void releaseRequest();
92 void cacheNegatively(); /* argh, why both? */
93 void invokeHandlers();
96 bool swapOutAble() const;
97 void swapOutFileClose();
98 const char *url() const;
100 int checkNegativeHit() const;
102 int validToSend() const;
103 int keepInMemory() const;
104 void createMemObject(const char *, const char *);
105 void dump(int debug_lvl
) const;
107 void hashInsert(const cache_key
*);
108 void registerAbort(STABH
* cb
, void *);
110 void setMemStatus(mem_status_t
);
111 void timestampsSet();
112 void unregisterAbort();
113 void destroyMemObject();
116 void delayAwareRead(int fd
, char *buf
, int len
, IOCB
*handler
, void *data
);
118 void setNoDelay (bool const);
119 bool modifiedSince(HttpRequest
* request
) const;
120 /* what store does this entry belong too ? */
121 virtual RefCount
<Store
> store() const;
124 RemovalPolicyNode repl
;
125 /* START OF ON-DISK STORE_META_STD TLV field */
130 uint64_t swap_file_sz
;
133 /* END OF ON-DISK STORE_META_STD */
140 u_short lock_count
; /* Assume < 65536! */
142 mem_status_t mem_status
:
145 ping_status_t ping_status
:
148 store_status_t store_status
:
151 swap_status_t swap_status
:
155 static size_t inUseCount();
156 static void getPublicByRequestMethod(StoreClient
* aClient
, HttpRequest
* request
, const HttpRequestMethod
& method
);
157 static void getPublicByRequest(StoreClient
* aClient
, HttpRequest
* request
);
158 static void getPublic(StoreClient
* aClient
, const char *uri
, const HttpRequestMethod
& method
);
160 virtual bool isNull()
165 void *operator new(size_t byteCount
);
166 void operator delete(void *address
);
167 void setReleaseFlag();
170 ESIElement::Pointer cachedESITree
;
172 /* append bytes to the buffer */
173 virtual void append(char const *, int len
);
174 /* disable sending content to the clients */
175 virtual void buffer();
176 /* flush any buffered content */
177 virtual void flush();
178 /* reduce the memory lock count on the entry */
179 virtual int unlock();
180 /* increate the memory lock count on the entry */
181 virtual int64_t objectLen() const;
182 virtual int64_t contentLen() const;
187 virtual void release();
190 static MemAllocator
*pool
;
192 bool validLength() const;
195 class NullStoreEntry
:public StoreEntry
199 static NullStoreEntry
*getInstance();
205 const char *getMD5Text() const;
206 _SQUID_INLINE_ HttpReply
const *getReply() const;
207 void write (StoreIOBuffer
){}
209 bool isEmpty () const {return true;}
211 virtual size_t bytesWanted(Range
<size_t> const aRange
) const { assert (aRange
.size());return aRange
.end
- 1;}
213 void operator delete(void *address
);
217 store_client_t
storeClientType() const{return STORE_MEM_CLIENT
;}
219 char const *getSerialisedMetaData();
220 bool swapoutPossible() {return false;}
225 static NullStoreEntry _instance
;
228 typedef void (*STOREGETCLIENT
) (StoreEntry
*, void *cbdata
);
231 /* Abstract base class that will replace the whole store and swapdir interface. */
233 class Store
: public RefCountable
238 static _SQUID_INLINE_ Store
&Root();
239 static void Root(Store
*);
240 static void Root(RefCount
<Store
>);
241 static void Stats(StoreEntry
* output
);
242 static void Maintain(void *unused
);
246 /* Handle pending callbacks - called by the event loop. */
247 virtual int callback() = 0;
248 /* create the resources needed for this store to operate */
249 virtual void create();
250 /* notify this store that its disk is full. TODO XXX move into a protected api call
251 * between store files and their stores, rather than a top level api call
253 virtual void diskFull();
254 /* Retrieve a store entry from the store */
256 virtual StoreEntry
* get
257 (const cache_key
*) = 0;
259 /* TODO: imeplement the async version */
261 (String
const key
, STOREGETCLIENT callback
, void *cbdata
) = 0;
263 /* prepare the store for use. The store need not be usable immediately,
264 * it should respond to readable() and writable() with true as soon
265 * as it can provide those services
267 virtual void init() = 0;
269 /* the maximum size the store will support in normal use. Inaccuracy is permitted,
270 * but may throw estimates for memory etc out of whack. */
271 virtual size_t maxSize() const = 0;
273 /* The minimum size the store will shrink to via normal housekeeping */
274 virtual size_t minSize() const = 0;
276 /* TODO: make these calls asynchronous */
277 virtual void stat(StoreEntry
&) const = 0; /* output stats to the provided store entry */
279 virtual void sync(); /* Sync the store prior to shutdown */
281 /* remove a Store entry from the store */
282 virtual void unlink (StoreEntry
&);
284 /* search in the store */
285 virtual StoreSearch
*search(String
const url
, HttpRequest
*) = 0;
287 /* pulled up from SwapDir for migration.... probably do not belong here */
288 virtual void reference(StoreEntry
&) = 0; /* Reference this object */
290 virtual void dereference(StoreEntry
&) = 0; /* Unreference this object */
292 virtual void maintain() = 0; /* perform regular maintenance should be private and self registered ... */
294 /* These should really be private */
295 virtual void updateSize(int64_t size
, int sign
) = 0;
298 static RefCount
<Store
> CurrentRoot
;
301 typedef RefCount
<Store
> StorePointer
;
303 SQUIDCEXTERN
size_t storeEntryInUse();
304 SQUIDCEXTERN
const char *storeEntryFlags(const StoreEntry
*);
305 extern void storeEntryReplaceObject(StoreEntry
*, HttpReply
*);
307 SQUIDCEXTERN StoreEntry
*storeGetPublic(const char *uri
, const HttpRequestMethod
& method
);
308 SQUIDCEXTERN StoreEntry
*storeGetPublicByRequest(HttpRequest
* request
);
309 SQUIDCEXTERN StoreEntry
*storeGetPublicByRequestMethod(HttpRequest
* request
, const HttpRequestMethod
& method
);
310 SQUIDCEXTERN StoreEntry
*storeCreateEntry(const char *, const char *, request_flags
, const HttpRequestMethod
&);
311 SQUIDCEXTERN
void storeInit(void);
312 extern void storeRegisterWithCacheManager(CacheManager
& manager
);
313 SQUIDCEXTERN
void storeConfigure(void);
314 SQUIDCEXTERN
void storeFreeMemory(void);
315 SQUIDCEXTERN
int expiresMoreThan(time_t, time_t);
318 storeAppendPrintf(StoreEntry
*, const char *,...) PRINTF_FORMAT_ARG2
;
320 SQUIDCEXTERN
void storeAppendPrintf();
322 SQUIDCEXTERN
void storeAppendVPrintf(StoreEntry
*, const char *, va_list ap
);
323 SQUIDCEXTERN
int storeTooManyDiskFilesOpen(void);
324 SQUIDCEXTERN
void storeHeapPositionUpdate(StoreEntry
*, SwapDir
*);
325 SQUIDCEXTERN
void storeSwapFileNumberSet(StoreEntry
* e
, sfileno filn
);
326 SQUIDCEXTERN
void storeFsInit(void);
327 SQUIDCEXTERN
void storeFsDone(void);
328 SQUIDCEXTERN
void storeReplAdd(const char *, REMOVALPOLICYCREATE
*);
329 extern FREE destroyStoreEntry
;
331 /* should be a subclass of Packer perhaps ? */
332 SQUIDCEXTERN
void packerToStoreInit(Packer
* p
, StoreEntry
* e
);
338 #endif /* SQUID_STORE_H */