5 * DEBUG: section 20 Storage Manager
6 * AUTHOR: Harvest Derived
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
37 #include "CacheManager.h"
38 #include "comm/Connection.h"
43 #include "mgr/Registration.h"
44 #include "StoreClient.h"
46 #include "HttpReply.h"
47 #include "HttpRequest.h"
48 #include "MemObject.h"
50 #include "StoreMeta.h"
53 #include "DelayPools.h"
56 #include "SquidTime.h"
57 #include "swap_log_op.h"
58 #include "mgr/StoreIoAction.h"
60 static STMCB storeWriteComplete
;
62 #define REBUILD_TIMESTAMP_DELTA_MAX 2
64 #define STORE_IN_MEM_BUCKETS (229)
67 /** \todo Convert these string constants to enum string-arrays generated */
69 const char *memStatusStr
[] = {
74 const char *pingStatusStr
[] = {
80 const char *storeStatusStr
[] = {
85 const char *swapStatusStr
[] = {
93 * This defines an repl type
96 typedef struct _storerepl_entry storerepl_entry_t
;
98 struct _storerepl_entry
{
100 REMOVALPOLICYCREATE
*create
;
103 static storerepl_entry_t
*storerepl_list
= NULL
;
107 * local function prototypes
109 static int getKeyCounter(void);
110 static OBJH storeCheckCachableStats
;
111 static EVH storeLateRelease
;
116 static Stack
<StoreEntry
*> LateReleaseStack
;
117 MemAllocator
*StoreEntry::pool
= NULL
;
119 StorePointer
Store::CurrentRoot
= NULL
;
122 Store::Root(Store
* aRoot
)
128 Store::Root(StorePointer aRoot
)
130 Root(aRoot
.getRaw());
134 Store::Stats(StoreEntry
* output
)
137 Root().stat(*output
);
153 Store::unlink (StoreEntry
&anEntry
)
155 fatal("Store::unlink on invalid Store\n");
159 StoreEntry::operator new (size_t bytecount
)
161 assert (bytecount
== sizeof (StoreEntry
));
164 pool
= memPoolCreate ("StoreEntry", bytecount
);
165 pool
->setChunkSize(2048 * 1024);
168 return pool
->alloc();
172 StoreEntry::operator delete (void *address
)
174 pool
->freeOne(address
);
178 StoreEntry::makePublic()
180 /* This object can be cached for a long time */
182 if (EBIT_TEST(flags
, ENTRY_CACHABLE
))
187 StoreEntry::makePrivate()
189 /* This object should never be cached at all */
191 releaseRequest(); /* delete object when not used */
192 /* releaseRequest clears ENTRY_CACHABLE flag */
196 StoreEntry::cacheNegatively()
198 /* This object may be negatively cached */
201 if (EBIT_TEST(flags
, ENTRY_CACHABLE
))
206 StoreEntry::inUseCount()
210 return pool
->getInUseCount();
214 StoreEntry::getMD5Text() const
216 return storeKeyText((const cache_key
*)key
);
222 StoreEntry::DeferReader(void *theContext
, CommRead
const &aRead
)
224 StoreEntry
*anEntry
= (StoreEntry
*)theContext
;
225 anEntry
->delayAwareRead(aRead
.conn
,
232 StoreEntry::delayAwareRead(const Comm::ConnectionPointer
&conn
, char *buf
, int len
, AsyncCall::Pointer callback
)
234 size_t amountToRead
= bytesWanted(Range
<size_t>(0, len
));
235 /* sketch: readdeferer* = getdeferer.
236 * ->deferRead (fd, buf, len, callback, DelayAwareRead, this)
239 if (amountToRead
== 0) {
241 /* read ahead limit */
242 /* Perhaps these two calls should both live in MemObject */
244 if (!mem_obj
->readAheadPolicyCanRead()) {
246 mem_obj
->delayRead(DeferredRead(DeferReader
, this, CommRead(conn
, buf
, len
, callback
)));
252 mem_obj
->mostBytesAllowed().delayRead(DeferredRead(DeferReader
, this, CommRead(conn
, buf
, len
, callback
)));
259 comm_read(conn
, buf
, amountToRead
, callback
);
263 StoreEntry::bytesWanted (Range
<size_t> const aRange
) const
265 assert (aRange
.size());
268 return aRange
.end
- 1;
270 #if URL_CHECKSUM_DEBUG
272 mem_obj
->checkUrlChecksum();
276 /* Always read *something* here - we haven't got the header yet */
277 if (EBIT_TEST(flags
, ENTRY_FWD_HDR_WAIT
))
278 return aRange
.end
- 1;
280 if (!mem_obj
->readAheadPolicyCanRead())
283 return mem_obj
->mostBytesWanted(aRange
.end
- 1);
287 StoreEntry::checkDeferRead(int fd
) const
289 return (bytesWanted(Range
<size_t>(0,INT_MAX
)) == 0);
293 StoreEntry::setNoDelay (bool const newValue
)
296 mem_obj
->setNoDelay(newValue
);
300 StoreEntry::storeClientType() const
302 /* The needed offset isn't in memory
303 * XXX TODO: this is wrong for range requests
304 * as the needed offset may *not* be 0, AND
305 * offset 0 in the memory object is the HTTP headers.
308 if (mem_obj
->inmem_lo
)
309 return STORE_DISK_CLIENT
;
311 if (EBIT_TEST(flags
, ENTRY_ABORTED
)) {
312 /* I don't think we should be adding clients to aborted entries */
313 debugs(20, 1, "storeClientType: adding to ENTRY_ABORTED entry");
314 return STORE_MEM_CLIENT
;
317 if (store_status
== STORE_OK
) {
318 /* the object has completed. */
320 if (mem_obj
->inmem_lo
== 0 && !isEmpty()) {
321 if (swap_status
== SWAPOUT_DONE
) {
322 if (mem_obj
->endOffset() == mem_obj
->object_sz
) {
323 /* hot object fully swapped in */
324 return STORE_MEM_CLIENT
;
327 /* Memory-only, or currently being swapped out */
328 return STORE_MEM_CLIENT
;
331 return STORE_DISK_CLIENT
;
334 /* here and past, entry is STORE_PENDING */
336 * If this is the first client, let it be the mem client
338 if (mem_obj
->nclients
== 1)
339 return STORE_MEM_CLIENT
;
342 * If there is no disk file to open yet, we must make this a
343 * mem client. If we can't open the swapin file before writing
344 * to the client, there is no guarantee that we will be able
345 * to open it later when we really need it.
347 if (swap_status
== SWAPOUT_NONE
)
348 return STORE_MEM_CLIENT
;
351 * otherwise, make subsequent clients read from disk so they
352 * can not delay the first, and vice-versa.
354 return STORE_DISK_CLIENT
;
357 StoreEntry::StoreEntry()
359 debugs(20, 3, HERE
<< "new StoreEntry " << this);
362 expires
= lastmod
= lastref
= timestamp
= -1;
368 StoreEntry::StoreEntry(const char *aUrl
, const char *aLogUrl
)
370 debugs(20, 3, HERE
<< "new StoreEntry " << this);
371 mem_obj
= new MemObject(aUrl
, aLogUrl
);
373 expires
= lastmod
= lastref
= timestamp
= -1;
380 StoreEntry::destroyMemObject()
382 debugs(20, 3, HERE
<< "destroyMemObject " << mem_obj
);
383 setMemStatus(NOT_IN_MEMORY
);
384 MemObject
*mem
= mem_obj
;
390 destroyStoreEntry(void *data
)
392 debugs(20, 3, HERE
<< "destroyStoreEntry: destroying " << data
);
393 StoreEntry
*e
= static_cast<StoreEntry
*>(static_cast<hash_link
*>(data
));
396 if (e
== NullStoreEntry::getInstance())
399 e
->destroyMemObject();
403 assert(e
->key
== NULL
);
408 /* ----- INTERFACE BETWEEN STORAGE MANAGER AND HASH TABLE FUNCTIONS --------- */
411 StoreEntry::hashInsert(const cache_key
* someKey
)
413 debugs(20, 3, "StoreEntry::hashInsert: Inserting Entry " << this << " key '" << storeKeyText(someKey
) << "'");
414 key
= storeKeyDup(someKey
);
415 hash_join(store_table
, this);
419 StoreEntry::hashDelete()
421 hash_remove_link(store_table
, this);
422 storeKeyFree((const cache_key
*)key
);
426 /* -------------------------------------------------------------------------- */
429 /* get rid of memory copy of the object */
431 StoreEntry::purgeMem()
436 debugs(20, 3, "StoreEntry::purgeMem: Freeing memory-copy of " << getMD5Text());
440 if (swap_status
!= SWAPOUT_DONE
)
444 /* RBC 20050104 this is wrong- memory ref counting
445 * is not at all equivalent to the store 'usage' concept
446 * which the replacement policies should be acting upon.
447 * specifically, object iteration within stores needs
448 * memory ref counting to prevent race conditions,
449 * but this should not influence store replacement.
456 debugs(20, 3, "StoreEntry::lock: key '" << getMD5Text() <<"' count=" <<
458 lastref
= squid_curtime
;
459 Store::Root().reference(*this);
463 StoreEntry::setReleaseFlag()
465 if (EBIT_TEST(flags
, RELEASE_REQUEST
))
468 debugs(20, 3, "StoreEntry::setReleaseFlag: '" << getMD5Text() << "'");
470 EBIT_SET(flags
, RELEASE_REQUEST
);
474 StoreEntry::releaseRequest()
476 if (EBIT_TEST(flags
, RELEASE_REQUEST
))
482 * Clear cachable flag here because we might get called before
483 * anyone else even looks at the cachability flag. Also, this
484 * prevents httpMakePublic from really setting a public key.
486 EBIT_CLR(flags
, ENTRY_CACHABLE
);
491 /* unlock object, return -1 if object get released after unlock
492 * otherwise lock_count */
497 debugs(20, 3, "StoreEntry::unlock: key '" << getMD5Text() << "' count=" << lock_count
);
500 return (int) lock_count
;
502 if (store_status
== STORE_PENDING
)
505 assert(storePendingNClients(this) == 0);
507 if (EBIT_TEST(flags
, RELEASE_REQUEST
))
509 else if (keepInMemory()) {
510 Store::Root().dereference(*this);
511 setMemStatus(IN_MEMORY
);
512 mem_obj
->unlinkRequest();
514 Store::Root().dereference(*this);
516 if (EBIT_TEST(flags
, KEY_PRIVATE
))
517 debugs(20, 1, "WARNING: " << __FILE__
<< ":" << __LINE__
<< ": found KEY_PRIVATE");
519 /* StoreEntry::purgeMem may free e */
527 StoreEntry::getPublicByRequestMethod (StoreClient
*aClient
, HttpRequest
* request
, const HttpRequestMethod
& method
)
530 StoreEntry
*result
= storeGetPublicByRequestMethod( request
, method
);
533 aClient
->created (NullStoreEntry::getInstance());
535 aClient
->created (result
);
539 StoreEntry::getPublicByRequest (StoreClient
*aClient
, HttpRequest
* request
)
542 StoreEntry
*result
= storeGetPublicByRequest (request
);
545 result
= NullStoreEntry::getInstance();
547 aClient
->created (result
);
551 StoreEntry::getPublic (StoreClient
*aClient
, const char *uri
, const HttpRequestMethod
& method
)
554 StoreEntry
*result
= storeGetPublic (uri
, method
);
557 result
= NullStoreEntry::getInstance();
559 aClient
->created (result
);
563 storeGetPublic(const char *uri
, const HttpRequestMethod
& method
)
565 return Store::Root().get(storeKeyPublic(uri
, method
));
569 storeGetPublicByRequestMethod(HttpRequest
* req
, const HttpRequestMethod
& method
)
571 return Store::Root().get(storeKeyPublicByRequestMethod(req
, method
));
575 storeGetPublicByRequest(HttpRequest
* req
)
577 StoreEntry
*e
= storeGetPublicByRequestMethod(req
, req
->method
);
579 if (e
== NULL
&& req
->method
== METHOD_HEAD
)
580 /* We can generate a HEAD reply from a cached GET object */
581 e
= storeGetPublicByRequestMethod(req
, METHOD_GET
);
589 static int key_counter
= 0;
591 if (++key_counter
< 0)
597 /* RBC 20050104 AFAICT this should become simpler:
598 * rather than reinserting with a special key it should be marked
599 * as 'released' and then cleaned up when refcounting indicates.
600 * the StoreHashIndex could well implement its 'released' in the
602 * Also, clean log writing should skip over ia,t
603 * Otherwise, we need a 'remove from the index but not the store
607 StoreEntry::setPrivateKey()
609 const cache_key
*newkey
;
611 if (key
&& EBIT_TEST(flags
, KEY_PRIVATE
))
612 return; /* is already private */
616 storeDirSwapLog(this, SWAP_LOG_DEL
);
621 if (mem_obj
!= NULL
) {
622 mem_obj
->id
= getKeyCounter();
623 newkey
= storeKeyPrivate(mem_obj
->url
, mem_obj
->method
, mem_obj
->id
);
625 newkey
= storeKeyPrivate("JUNK", METHOD_NONE
, getKeyCounter());
628 assert(hash_lookup(store_table
, newkey
) == NULL
);
629 EBIT_SET(flags
, KEY_PRIVATE
);
634 StoreEntry::setPublicKey()
636 StoreEntry
*e2
= NULL
;
637 const cache_key
*newkey
;
639 if (key
&& !EBIT_TEST(flags
, KEY_PRIVATE
))
640 return; /* is already public */
645 * We can't make RELEASE_REQUEST objects public. Depending on
646 * when RELEASE_REQUEST gets set, we might not be swapping out
647 * the object. If we're not swapping out, then subsequent
648 * store clients won't be able to access object data which has
649 * been freed from memory.
651 * If RELEASE_REQUEST is set, then ENTRY_CACHABLE should not
652 * be set, and StoreEntry::setPublicKey() should not be called.
654 #if MORE_DEBUG_OUTPUT
656 if (EBIT_TEST(flags
, RELEASE_REQUEST
))
657 debugs(20, 1, "assertion failed: RELEASE key " << key
<< ", url " << mem_obj
->url
);
661 assert(!EBIT_TEST(flags
, RELEASE_REQUEST
));
663 if (mem_obj
->request
) {
664 HttpRequest
*request
= mem_obj
->request
;
666 if (!mem_obj
->vary_headers
) {
667 /* First handle the case where the object no longer varies */
668 safe_free(request
->vary_headers
);
670 if (request
->vary_headers
&& strcmp(request
->vary_headers
, mem_obj
->vary_headers
) != 0) {
671 /* Oops.. the variance has changed. Kill the base object
672 * to record the new variance key
674 safe_free(request
->vary_headers
); /* free old "bad" variance key */
675 StoreEntry
*pe
= storeGetPublic(mem_obj
->url
, mem_obj
->method
);
681 /* Make sure the request knows the variance status */
682 if (!request
->vary_headers
) {
683 const char *vary
= httpMakeVaryMark(request
, mem_obj
->getReply());
686 request
->vary_headers
= xstrdup(vary
);
690 if (mem_obj
->vary_headers
&& !storeGetPublic(mem_obj
->url
, mem_obj
->method
)) {
691 /* Create "vary" base object */
693 StoreEntry
*pe
= storeCreateEntry(mem_obj
->url
, mem_obj
->log_url
, request
->flags
, request
->method
);
694 /* We are allowed to do this typecast */
695 HttpReply
*rep
= new HttpReply
;
696 rep
->setHeaders(HTTP_OK
, "Internal marker object", "x-squid-internal/vary", -1, -1, squid_curtime
+ 100000);
697 vary
= mem_obj
->getReply()->header
.getList(HDR_VARY
);
700 /* Again, we own this structure layout */
701 rep
->header
.putStr(HDR_VARY
, vary
.termedBuf());
705 #if X_ACCELERATOR_VARY
706 vary
= mem_obj
->getReply()->header
.getList(HDR_X_ACCELERATOR_VARY
);
708 if (vary
.defined()) {
709 /* Again, we own this structure layout */
710 rep
->header
.putStr(HDR_X_ACCELERATOR_VARY
, vary
.termedBuf());
715 pe
->replaceHttpReply(rep
);
726 newkey
= storeKeyPublicByRequest(mem_obj
->request
);
728 newkey
= storeKeyPublic(mem_obj
->url
, mem_obj
->method
);
730 if ((e2
= (StoreEntry
*) hash_lookup(store_table
, newkey
))) {
731 debugs(20, 3, "StoreEntry::setPublicKey: Making old '" << mem_obj
->url
<< "' private.");
735 if (mem_obj
->request
)
736 newkey
= storeKeyPublicByRequest(mem_obj
->request
);
738 newkey
= storeKeyPublic(mem_obj
->url
, mem_obj
->method
);
744 EBIT_CLR(flags
, KEY_PRIVATE
);
749 storeDirSwapLog(this, SWAP_LOG_ADD
);
753 storeCreateEntry(const char *url
, const char *log_url
, request_flags flags
, const HttpRequestMethod
& method
)
755 StoreEntry
*e
= NULL
;
756 MemObject
*mem
= NULL
;
757 debugs(20, 3, "storeCreateEntry: '" << url
<< "'");
759 e
= new StoreEntry(url
, log_url
);
760 e
->lock_count
= 1; /* Note lock here w/o calling storeLock() */
762 mem
->method
= method
;
764 if (neighbors_do_private_keys
|| !flags
.hierarchical
)
769 if (flags
.cachable
) {
770 EBIT_SET(e
->flags
, ENTRY_CACHABLE
);
771 EBIT_CLR(e
->flags
, RELEASE_REQUEST
);
773 /* StoreEntry::releaseRequest() clears ENTRY_CACHABLE */
777 e
->store_status
= STORE_PENDING
;
778 e
->setMemStatus(NOT_IN_MEMORY
);
779 e
->swap_status
= SWAPOUT_NONE
;
783 e
->lastref
= squid_curtime
;
784 e
->timestamp
= -1; /* set in StoreEntry::timestampsSet() */
785 e
->ping_status
= PING_NONE
;
786 EBIT_SET(e
->flags
, ENTRY_VALIDATED
);
790 /* Mark object as expired */
792 StoreEntry::expireNow()
794 debugs(20, 3, "StoreEntry::expireNow: '" << getMD5Text() << "'");
795 expires
= squid_curtime
;
799 storeWriteComplete (void *data
, StoreIOBuffer wroteBuffer
)
801 PROF_start(storeWriteComplete
);
802 StoreEntry
*e
= (StoreEntry
*)data
;
804 if (EBIT_TEST(e
->flags
, DELAY_SENDING
)) {
805 PROF_stop(storeWriteComplete
);
810 PROF_stop(storeWriteComplete
);
814 StoreEntry::write (StoreIOBuffer writeBuffer
)
816 assert(mem_obj
!= NULL
);
817 /* This assert will change when we teach the store to update */
818 PROF_start(StoreEntry_write
);
819 assert(store_status
== STORE_PENDING
);
821 if (!writeBuffer
.length
) {
822 /* the headers are received already, but we have not received
823 * any body data. There are BROKEN abuses of HTTP which require
824 * the headers to be passed along before any body data - see
825 * http://developer.apple.com/documentation/QuickTime/QTSS/Concepts/chapter_2_section_14.html
826 * for an example of such bad behaviour. To accomodate this, if
827 * we have a empty write arrive, we flush to our clients.
830 PROF_stop(StoreEntry_write
);
835 debugs(20, 5, "storeWrite: writing " << writeBuffer
.length
<< " bytes for '" << getMD5Text() << "'");
836 PROF_stop(StoreEntry_write
);
837 storeGetMemSpace(writeBuffer
.length
);
838 mem_obj
->write (writeBuffer
, storeWriteComplete
, this);
841 /* Append incoming data from a primary server to an entry. */
843 StoreEntry::append(char const *buf
, int len
)
845 assert(mem_obj
!= NULL
);
847 assert(store_status
== STORE_PENDING
);
849 StoreIOBuffer tempBuffer
;
850 tempBuffer
.data
= (char *)buf
;
851 tempBuffer
.length
= len
;
853 * XXX sigh, offset might be < 0 here, but it gets "corrected"
854 * later. This offset crap is such a mess.
856 tempBuffer
.offset
= mem_obj
->endOffset() - (getReply() ? getReply()->hdr_sz
: 0);
862 storeAppendPrintf(StoreEntry
* e
, const char *fmt
,...)
867 storeAppendVPrintf(e
, fmt
, args
);
871 /* used be storeAppendPrintf and Packer */
873 storeAppendVPrintf(StoreEntry
* e
, const char *fmt
, va_list vargs
)
875 LOCAL_ARRAY(char, buf
, 4096);
877 vsnprintf(buf
, 4096, fmt
, vargs
);
878 e
->append(buf
, strlen(buf
));
881 struct _store_check_cachable_hist
{
885 int not_entry_cachable
;
886 int wrong_content_length
;
891 int too_many_open_files
;
892 int too_many_open_fds
;
898 } store_check_cachable_hist
;
901 storeTooManyDiskFilesOpen(void)
903 if (Config
.max_open_disk_fds
== 0)
906 if (store_open_disk_fd
> Config
.max_open_disk_fds
)
913 StoreEntry::checkTooSmall()
915 if (EBIT_TEST(flags
, ENTRY_SPECIAL
))
918 if (STORE_OK
== store_status
)
919 if (mem_obj
->object_sz
< 0 ||
920 mem_obj
->object_sz
< Config
.Store
.minObjectSize
)
922 if (getReply()->content_length
> -1)
923 if (getReply()->content_length
< Config
.Store
.minObjectSize
)
929 StoreEntry::checkCachable()
931 #if CACHE_ALL_METHODS
933 if (mem_obj
->method
!= METHOD_GET
) {
934 debugs(20, 2, "StoreEntry::checkCachable: NO: non-GET method");
935 store_check_cachable_hist
.no
.non_get
++;
938 if (store_status
== STORE_OK
&& EBIT_TEST(flags
, ENTRY_BAD_LENGTH
)) {
939 debugs(20, 2, "StoreEntry::checkCachable: NO: wrong content-length");
940 store_check_cachable_hist
.no
.wrong_content_length
++;
941 } else if (!EBIT_TEST(flags
, ENTRY_CACHABLE
)) {
942 debugs(20, 2, "StoreEntry::checkCachable: NO: not cachable");
943 store_check_cachable_hist
.no
.not_entry_cachable
++;
944 } else if (EBIT_TEST(flags
, ENTRY_NEGCACHED
)) {
945 debugs(20, 3, "StoreEntry::checkCachable: NO: negative cached");
946 store_check_cachable_hist
.no
.negative_cached
++;
947 return 0; /* avoid release call below */
948 } else if ((getReply()->content_length
> 0 &&
949 getReply()->content_length
950 > Config
.Store
.maxObjectSize
) ||
951 mem_obj
->endOffset() > Config
.Store
.maxObjectSize
) {
952 debugs(20, 2, "StoreEntry::checkCachable: NO: too big");
953 store_check_cachable_hist
.no
.too_big
++;
954 } else if (getReply()->content_length
> Config
.Store
.maxObjectSize
) {
955 debugs(20, 2, "StoreEntry::checkCachable: NO: too big");
956 store_check_cachable_hist
.no
.too_big
++;
957 } else if (checkTooSmall()) {
958 debugs(20, 2, "StoreEntry::checkCachable: NO: too small");
959 store_check_cachable_hist
.no
.too_small
++;
960 } else if (EBIT_TEST(flags
, KEY_PRIVATE
)) {
961 debugs(20, 3, "StoreEntry::checkCachable: NO: private key");
962 store_check_cachable_hist
.no
.private_key
++;
963 } else if (swap_status
!= SWAPOUT_NONE
) {
965 * here we checked the swap_status because the remaining
966 * cases are only relevant only if we haven't started swapping
967 * out the object yet.
970 } else if (storeTooManyDiskFilesOpen()) {
971 debugs(20, 2, "StoreEntry::checkCachable: NO: too many disk files open");
972 store_check_cachable_hist
.no
.too_many_open_files
++;
973 } else if (fdNFree() < RESERVED_FD
) {
974 debugs(20, 2, "StoreEntry::checkCachable: NO: too many FD's open");
975 store_check_cachable_hist
.no
.too_many_open_fds
++;
977 store_check_cachable_hist
.yes
.Default
++;
982 /* StoreEntry::releaseRequest() cleared ENTRY_CACHABLE */
987 storeCheckCachableStats(StoreEntry
*sentry
)
989 storeAppendPrintf(sentry
, "Category\t Count\n");
991 #if CACHE_ALL_METHODS
993 storeAppendPrintf(sentry
, "no.non_get\t%d\n",
994 store_check_cachable_hist
.no
.non_get
);
997 storeAppendPrintf(sentry
, "no.not_entry_cachable\t%d\n",
998 store_check_cachable_hist
.no
.not_entry_cachable
);
999 storeAppendPrintf(sentry
, "no.wrong_content_length\t%d\n",
1000 store_check_cachable_hist
.no
.wrong_content_length
);
1001 storeAppendPrintf(sentry
, "no.negative_cached\t%d\n",
1002 store_check_cachable_hist
.no
.negative_cached
);
1003 storeAppendPrintf(sentry
, "no.too_big\t%d\n",
1004 store_check_cachable_hist
.no
.too_big
);
1005 storeAppendPrintf(sentry
, "no.too_small\t%d\n",
1006 store_check_cachable_hist
.no
.too_small
);
1007 storeAppendPrintf(sentry
, "no.private_key\t%d\n",
1008 store_check_cachable_hist
.no
.private_key
);
1009 storeAppendPrintf(sentry
, "no.too_many_open_files\t%d\n",
1010 store_check_cachable_hist
.no
.too_many_open_files
);
1011 storeAppendPrintf(sentry
, "no.too_many_open_fds\t%d\n",
1012 store_check_cachable_hist
.no
.too_many_open_fds
);
1013 storeAppendPrintf(sentry
, "yes.default\t%d\n",
1014 store_check_cachable_hist
.yes
.Default
);
1018 StoreEntry::complete()
1020 debugs(20, 3, "storeComplete: '" << getMD5Text() << "'");
1022 if (store_status
!= STORE_PENDING
) {
1024 * if we're not STORE_PENDING, then probably we got aborted
1025 * and there should be NO clients on this entry
1027 assert(EBIT_TEST(flags
, ENTRY_ABORTED
));
1028 assert(mem_obj
->nclients
== 0);
1032 /* This is suspect: mem obj offsets include the headers. do we adjust for that
1033 * in use of object_sz?
1035 mem_obj
->object_sz
= mem_obj
->endOffset();
1037 store_status
= STORE_OK
;
1039 assert(mem_status
== NOT_IN_MEMORY
);
1041 if (!validLength()) {
1042 EBIT_SET(flags
, ENTRY_BAD_LENGTH
);
1046 #if USE_CACHE_DIGESTS
1047 if (mem_obj
->request
)
1048 mem_obj
->request
->hier
.store_complete_stop
= current_time
;
1052 * We used to call invokeHandlers, then storeSwapOut. However,
1053 * Madhukar Reddy <myreddy@persistence.com> reported that
1054 * responses without content length would sometimes get released
1055 * in client_side, thinking that the response is incomplete.
1061 * Someone wants to abort this transfer. Set the reason in the
1062 * request structure, call the server-side callback and mark the
1063 * entry for releasing
1068 statCounter
.aborted_requests
++;
1069 assert(store_status
== STORE_PENDING
);
1070 assert(mem_obj
!= NULL
);
1071 debugs(20, 6, "storeAbort: " << getMD5Text());
1073 lock(); /* lock while aborting */
1078 EBIT_SET(flags
, ENTRY_ABORTED
);
1080 setMemStatus(NOT_IN_MEMORY
);
1082 store_status
= STORE_OK
;
1085 * We assign an object length here. The only other place we assign
1086 * the object length is in storeComplete()
1088 /* RBC: What do we need an object length for? we've just aborted the
1089 * request, the request is private and negatively cached. Surely
1090 * the object length is inappropriate to set.
1092 mem_obj
->object_sz
= mem_obj
->endOffset();
1094 /* Notify the server side */
1098 * Should we check abort.data for validity?
1100 if (mem_obj
->abort
.callback
) {
1101 if (!cbdataReferenceValid(mem_obj
->abort
.data
))
1102 debugs(20,1,HERE
<< "queueing event when abort.data is not valid");
1103 eventAdd("mem_obj->abort.callback",
1104 mem_obj
->abort
.callback
,
1105 mem_obj
->abort
.data
,
1111 /* XXX Should we reverse these two, so that there is no
1112 * unneeded disk swapping triggered?
1114 /* Notify the client side */
1117 /* Close any swapout file */
1120 unlock(); /* unlock */
1124 * Clear Memory storage to accommodate the given object len
1127 storeGetMemSpace(int size
)
1129 PROF_start(storeGetMemSpace
);
1130 StoreEntry
*e
= NULL
;
1132 static time_t last_check
= 0;
1133 size_t pages_needed
;
1134 RemovalPurgeWalker
*walker
;
1136 if (squid_curtime
== last_check
) {
1137 PROF_stop(storeGetMemSpace
);
1141 last_check
= squid_curtime
;
1143 pages_needed
= (size
/ SM_PAGE_SIZE
) + 1;
1145 if (mem_node::InUseCount() + pages_needed
< store_pages_max
) {
1146 PROF_stop(storeGetMemSpace
);
1150 debugs(20, 2, "storeGetMemSpace: Starting, need " << pages_needed
<<
1153 /* XXX what to set as max_scan here? */
1154 walker
= mem_policy
->PurgeInit(mem_policy
, 100000);
1156 while ((e
= walker
->Next(walker
))) {
1160 if (mem_node::InUseCount() + pages_needed
< store_pages_max
)
1164 walker
->Done(walker
);
1165 debugs(20, 3, "storeGetMemSpace stats:");
1166 debugs(20, 3, " " << std::setw(6) << hot_obj_count
<< " HOT objects");
1167 debugs(20, 3, " " << std::setw(6) << released
<< " were released");
1168 PROF_stop(storeGetMemSpace
);
1172 /* thunk through to Store::Root().maintain(). Note that this would be better still
1173 * if registered against the root store itself, but that requires more complex
1174 * update logic - bigger fish to fry first. Long term each store when
1175 * it becomes active will self register
1178 Store::Maintain(void *notused
)
1180 Store::Root().maintain();
1182 /* Reregister a maintain event .. */
1183 eventAdd("MaintainSwapSpace", Maintain
, NULL
, 1.0, 1);
1187 /* The maximum objects to scan for maintain storage space */
1188 #define MAINTAIN_MAX_SCAN 1024
1189 #define MAINTAIN_MAX_REMOVE 64
1192 * This routine is to be called by main loop in main.c.
1193 * It removes expired objects on only one bucket for each time called.
1195 * This should get called 1/s from main().
1198 StoreController::maintain()
1200 static time_t last_warn_time
= 0;
1202 PROF_start(storeMaintainSwapSpace
);
1203 swapDir
->maintain();
1205 /* this should be emitted by the oversize dir, not globally */
1207 if (store_swap_size
> Store::Root().maxSize()) {
1208 if (squid_curtime
- last_warn_time
> 10) {
1209 debugs(20, 0, "WARNING: Disk space over limit: " << store_swap_size
<< " KB > "
1210 << Store::Root().maxSize() << " KB");
1211 last_warn_time
= squid_curtime
;
1215 PROF_stop(storeMaintainSwapSpace
);
1218 /* release an object from a cache */
1220 StoreEntry::release()
1222 PROF_start(storeRelease
);
1223 debugs(20, 3, "storeRelease: Releasing: '" << getMD5Text() << "'");
1224 /* If, for any reason we can't discard this object because of an
1225 * outstanding request, mark it for pending release */
1229 debugs(20, 3, "storeRelease: Only setting RELEASE_REQUEST bit");
1231 PROF_stop(storeRelease
);
1235 if (StoreController::store_dirs_rebuilding
&& swap_filen
> -1) {
1241 if (swap_filen
> -1) {
1243 * Fake a call to StoreEntry->lock() When rebuilding is done,
1244 * we'll just call StoreEntry->unlock() on these.
1248 LateReleaseStack
.push_back(this);
1249 PROF_stop(storeRelease
);
1252 destroyStoreEntry(static_cast<hash_link
*>(this));
1256 storeLog(STORE_LOG_RELEASE
, this);
1258 if (swap_filen
> -1) {
1261 if (swap_status
== SWAPOUT_DONE
)
1262 if (EBIT_TEST(flags
, ENTRY_VALIDATED
))
1263 store()->updateSize(swap_file_sz
, -1);
1265 if (!EBIT_TEST(flags
, KEY_PRIVATE
))
1266 storeDirSwapLog(this, SWAP_LOG_DEL
);
1269 /* From 2.4. I think we do this in storeUnlink? */
1270 storeSwapFileNumberSet(this, -1);
1276 setMemStatus(NOT_IN_MEMORY
);
1277 destroyStoreEntry(static_cast<hash_link
*>(this));
1278 PROF_stop(storeRelease
);
1282 storeLateRelease(void *unused
)
1288 if (StoreController::store_dirs_rebuilding
) {
1289 eventAdd("storeLateRelease", storeLateRelease
, NULL
, 1.0, 1);
1293 for (i
= 0; i
< 10; i
++) {
1294 e
= LateReleaseStack
.pop();
1298 debugs(20, 1, "storeLateRelease: released " << n
<< " objects");
1306 eventAdd("storeLateRelease", storeLateRelease
, NULL
, 0.0, 1);
1309 /* return 1 if a store entry is locked */
1311 StoreEntry::locked() const
1316 if (swap_status
== SWAPOUT_WRITING
)
1319 if (store_status
== STORE_PENDING
)
1323 * SPECIAL, PUBLIC entries should be "locked"
1325 if (EBIT_TEST(flags
, ENTRY_SPECIAL
))
1326 if (!EBIT_TEST(flags
, KEY_PRIVATE
))
1333 StoreEntry::validLength() const
1336 const HttpReply
*reply
;
1337 assert(mem_obj
!= NULL
);
1339 debugs(20, 3, "storeEntryValidLength: Checking '" << getMD5Text() << "'");
1340 debugs(20, 5, "storeEntryValidLength: object_len = " <<
1342 debugs(20, 5, "storeEntryValidLength: hdr_sz = " << reply
->hdr_sz
);
1343 debugs(20, 5, "storeEntryValidLength: content_length = " << reply
->content_length
);
1345 if (reply
->content_length
< 0) {
1346 debugs(20, 5, "storeEntryValidLength: Unspecified content length: " << getMD5Text());
1350 if (reply
->hdr_sz
== 0) {
1351 debugs(20, 5, "storeEntryValidLength: Zero header size: " << getMD5Text());
1355 if (mem_obj
->method
== METHOD_HEAD
) {
1356 debugs(20, 5, "storeEntryValidLength: HEAD request: " << getMD5Text());
1360 if (reply
->sline
.status
== HTTP_NOT_MODIFIED
)
1363 if (reply
->sline
.status
== HTTP_NO_CONTENT
)
1366 diff
= reply
->hdr_sz
+ reply
->content_length
- objectLen();
1371 debugs(20, 3, "storeEntryValidLength: " << (diff
< 0 ? -diff
: diff
) << " bytes too " << (diff
< 0 ? "big" : "small") <<"; '" << getMD5Text() << "'" );
1377 storeRegisterWithCacheManager(void)
1379 Mgr::RegisterAction("storedir", "Store Directory Stats", Store::Stats
, 0, 1);
1380 Mgr::RegisterAction("store_io", "Store IO Interface Stats", &Mgr::StoreIoAction::Create
, 0, 1);
1381 Mgr::RegisterAction("store_check_cachable_stats", "storeCheckCachable() Stats",
1382 storeCheckCachableStats
, 0, 1);
1389 mem_policy
= createRemovalPolicy(Config
.memPolicy
);
1392 eventAdd("storeLateRelease", storeLateRelease
, NULL
, 1.0, 1);
1393 Store::Root().init();
1394 storeRebuildStart();
1396 storeRegisterWithCacheManager();
1400 storeConfigure(void)
1402 store_swap_high
= (long) (((float) Store::Root().maxSize() *
1403 (float) Config
.Swap
.highWaterMark
) / (float) 100);
1404 store_swap_low
= (long) (((float) Store::Root().maxSize() *
1405 (float) Config
.Swap
.lowWaterMark
) / (float) 100);
1406 store_pages_max
= Config
.memMaxSize
/ sizeof(mem_node
);
1410 StoreEntry::keepInMemory() const
1412 if (mem_obj
== NULL
)
1415 if (mem_obj
->data_hdr
.size() == 0)
1418 if (mem_obj
->inmem_lo
!= 0)
1421 if (!Config
.onoff
.memory_cache_first
&& swap_status
== SWAPOUT_DONE
&& refcount
== 1)
1428 StoreEntry::checkNegativeHit() const
1430 if (!EBIT_TEST(flags
, ENTRY_NEGCACHED
))
1433 if (expires
<= squid_curtime
)
1436 if (store_status
!= STORE_OK
)
1443 * Set object for negative caching.
1444 * Preserves any expiry information given by the server.
1445 * In absence of proper expiry info it will set to expire immediately,
1446 * or with HTTP-violations enabled the configured negative-TTL is observed
1449 StoreEntry::negativeCache()
1452 #if USE_HTTP_VIOLATIONS
1453 expires
= squid_curtime
+ Config
.negativeTtl
;
1455 expires
= squid_curtime
;
1457 EBIT_SET(flags
, ENTRY_NEGCACHED
);
1461 storeFreeMemory(void)
1464 #if USE_CACHE_DIGESTS
1467 cacheDigestDestroy(store_digest
);
1471 store_digest
= NULL
;
1475 expiresMoreThan(time_t expires
, time_t when
)
1477 if (expires
< 0) /* No Expires given */
1480 return (expires
> (squid_curtime
+ when
));
1484 StoreEntry::validToSend() const
1486 if (EBIT_TEST(flags
, RELEASE_REQUEST
))
1489 if (EBIT_TEST(flags
, ENTRY_NEGCACHED
))
1490 if (expires
<= squid_curtime
)
1493 if (EBIT_TEST(flags
, ENTRY_ABORTED
))
1500 StoreEntry::timestampsSet()
1502 const HttpReply
*reply
= getReply();
1503 time_t served_date
= reply
->date
;
1504 int age
= reply
->header
.getInt(HDR_AGE
);
1505 /* Compute the timestamp, mimicking RFC2616 section 13.2.3. */
1506 /* make sure that 0 <= served_date <= squid_curtime */
1508 if (served_date
< 0 || served_date
> squid_curtime
)
1509 served_date
= squid_curtime
;
1512 * Compensate with Age header if origin server clock is ahead
1513 * of us and there is a cache in between us and the origin
1514 * server. But DONT compensate if the age value is larger than
1515 * squid_curtime because it results in a negative served_date.
1517 if (age
> squid_curtime
- served_date
)
1518 if (squid_curtime
> age
)
1519 served_date
= squid_curtime
- age
;
1521 // compensate for Squid-to-server and server-to-Squid delays
1522 if (mem_obj
&& mem_obj
->request
) {
1523 const time_t request_sent
=
1524 mem_obj
->request
->hier
.peer_http_request_sent
.tv_sec
;
1525 if (0 < request_sent
&& request_sent
< squid_curtime
)
1526 served_date
-= (squid_curtime
- request_sent
);
1529 if (reply
->expires
> 0 && reply
->date
> -1)
1530 expires
= served_date
+ (reply
->expires
- reply
->date
);
1532 expires
= reply
->expires
;
1534 lastmod
= reply
->last_modified
;
1536 timestamp
= served_date
;
1540 StoreEntry::registerAbort(STABH
* cb
, void *data
)
1543 assert(mem_obj
->abort
.callback
== NULL
);
1544 mem_obj
->abort
.callback
= cb
;
1545 mem_obj
->abort
.data
= cbdataReference(data
);
1549 StoreEntry::unregisterAbort()
1552 if (mem_obj
->abort
.callback
) {
1553 mem_obj
->abort
.callback
= NULL
;
1554 cbdataReferenceDone(mem_obj
->abort
.data
);
1559 StoreEntry::dump(int l
) const
1561 debugs(20, l
, "StoreEntry->key: " << getMD5Text());
1562 debugs(20, l
, "StoreEntry->next: " << next
);
1563 debugs(20, l
, "StoreEntry->mem_obj: " << mem_obj
);
1564 debugs(20, l
, "StoreEntry->timestamp: " << timestamp
);
1565 debugs(20, l
, "StoreEntry->lastref: " << lastref
);
1566 debugs(20, l
, "StoreEntry->expires: " << expires
);
1567 debugs(20, l
, "StoreEntry->lastmod: " << lastmod
);
1568 debugs(20, l
, "StoreEntry->swap_file_sz: " << swap_file_sz
);
1569 debugs(20, l
, "StoreEntry->refcount: " << refcount
);
1570 debugs(20, l
, "StoreEntry->flags: " << storeEntryFlags(this));
1571 debugs(20, l
, "StoreEntry->swap_dirn: " << swap_dirn
);
1572 debugs(20, l
, "StoreEntry->swap_filen: " << swap_filen
);
1573 debugs(20, l
, "StoreEntry->lock_count: " << lock_count
);
1574 debugs(20, l
, "StoreEntry->mem_status: " << mem_status
);
1575 debugs(20, l
, "StoreEntry->ping_status: " << ping_status
);
1576 debugs(20, l
, "StoreEntry->store_status: " << store_status
);
1577 debugs(20, l
, "StoreEntry->swap_status: " << swap_status
);
1581 * NOTE, this function assumes only two mem states
1584 StoreEntry::setMemStatus(mem_status_t new_status
)
1586 if (new_status
== mem_status
)
1589 assert(mem_obj
!= NULL
);
1591 if (new_status
== IN_MEMORY
) {
1592 assert(mem_obj
->inmem_lo
== 0);
1594 if (EBIT_TEST(flags
, ENTRY_SPECIAL
)) {
1595 debugs(20, 4, "StoreEntry::setMemStatus: not inserting special " << mem_obj
->url
<< " into policy");
1597 mem_policy
->Add(mem_policy
, this, &mem_obj
->repl
);
1598 debugs(20, 4, "StoreEntry::setMemStatus: inserted mem node " << mem_obj
->url
);
1603 if (EBIT_TEST(flags
, ENTRY_SPECIAL
)) {
1604 debugs(20, 4, "StoreEntry::setMemStatus: special entry " << mem_obj
->url
);
1606 mem_policy
->Remove(mem_policy
, this, &mem_obj
->repl
);
1607 debugs(20, 4, "StoreEntry::setMemStatus: removed mem node " << mem_obj
->url
);
1613 mem_status
= new_status
;
1617 StoreEntry::url() const
1620 return "[null_entry]";
1621 else if (mem_obj
== NULL
)
1622 return "[null_mem_obj]";
1624 return mem_obj
->url
;
1628 StoreEntry::createMemObject(const char *aUrl
, const char *aLogUrl
)
1633 mem_obj
= new MemObject(aUrl
, aLogUrl
);
1636 /* this just sets DELAY_SENDING */
1638 StoreEntry::buffer()
1640 EBIT_SET(flags
, DELAY_SENDING
);
1643 /* this just clears DELAY_SENDING and Invokes the handlers */
1647 if (EBIT_TEST(flags
, DELAY_SENDING
)) {
1648 EBIT_CLR(flags
, DELAY_SENDING
);
1654 StoreEntry::objectLen() const
1656 assert(mem_obj
!= NULL
);
1657 return mem_obj
->object_sz
;
1661 StoreEntry::contentLen() const
1663 assert(mem_obj
!= NULL
);
1664 assert(getReply() != NULL
);
1665 return objectLen() - getReply()->hdr_sz
;
1669 StoreEntry::getReply () const
1671 if (NULL
== mem_obj
)
1674 return mem_obj
->getReply();
1681 debugs(20, 3, "StoreEntry::reset: " << url());
1683 HttpReply
*rep
= (HttpReply
*) getReply(); // bypass const
1685 expires
= lastmod
= timestamp
= -1;
1691 * This routine calls the SETUP routine for each fs type.
1692 * I don't know where the best place for this is, and I'm not going to shuffle
1693 * around large chunks of code right now (that can be done once its working.)
1702 * called to add another store removal policy module
1705 storeReplAdd(const char *type
, REMOVALPOLICYCREATE
* create
)
1709 /* find the number of currently known repl types */
1710 for (i
= 0; storerepl_list
&& storerepl_list
[i
].typestr
; i
++) {
1711 if (strcmp(storerepl_list
[i
].typestr
, type
) == 0) {
1712 debugs(20, 1, "WARNING: Trying to load store replacement policy " << type
<< " twice.");
1717 /* add the new type */
1718 storerepl_list
= static_cast<storerepl_entry_t
*>(xrealloc(storerepl_list
, (i
+ 2) * sizeof(storerepl_entry_t
)));
1720 memset(&storerepl_list
[i
+ 1], 0, sizeof(storerepl_entry_t
));
1722 storerepl_list
[i
].typestr
= type
;
1724 storerepl_list
[i
].create
= create
;
1728 * Create a removal policy instance
1731 createRemovalPolicy(RemovalPolicySettings
* settings
)
1733 storerepl_entry_t
*r
;
1735 for (r
= storerepl_list
; r
&& r
->typestr
; r
++) {
1736 if (strcmp(r
->typestr
, settings
->type
) == 0)
1737 return r
->create(settings
->args
);
1740 debugs(20, 1, "ERROR: Unknown policy " << settings
->type
);
1741 debugs(20, 1, "ERROR: Be sure to have set cache_replacement_policy");
1742 debugs(20, 1, "ERROR: and memory_replacement_policy in squid.conf!");
1743 fatalf("ERROR: Unknown policy %s\n", settings
->type
);
1744 return NULL
; /* NOTREACHED */
1749 storeSwapFileNumberSet(StoreEntry
* e
, sfileno filn
)
1751 if (e
->swap_file_number
== filn
)
1756 storeDirMapBitReset(e
->swap_file_number
);
1757 storeDirLRUDelete(e
);
1758 e
->swap_file_number
= -1;
1760 assert(-1 == e
->swap_file_number
);
1761 storeDirMapBitSet(e
->swap_file_number
= filn
);
1770 * Replace a store entry with
1771 * a new reply. This eats the reply.
1774 StoreEntry::replaceHttpReply(HttpReply
*rep
)
1776 debugs(20, 3, "StoreEntry::replaceHttpReply: " << url());
1780 debugs(20, 0, "Attempt to replace object with no in-memory representation");
1784 mem_obj
->replaceHttpReply(rep
);
1786 /* TODO: when we store headers serparately remove the header portion */
1787 /* TODO: mark the length of the headers ? */
1788 /* We ONLY want the headers */
1789 packerToStoreInit(&p
, this);
1793 getReply()->packHeadersInto(&p
);
1795 rep
->hdr_sz
= mem_obj
->endOffset();
1797 httpBodyPackInto(&getReply()->body
, &p
);
1804 StoreEntry::getSerialisedMetaData()
1806 StoreMeta
*tlv_list
= storeSwapMetaBuild(this);
1808 char *result
= storeSwapMetaPack(tlv_list
, &swap_hdr_sz
);
1809 storeSwapTLVFree(tlv_list
);
1810 assert (swap_hdr_sz
>= 0);
1811 mem_obj
->swap_hdr_sz
= (size_t) swap_hdr_sz
;
1816 StoreEntry::swapoutPossible()
1818 /* should we swap something out to disk? */
1819 debugs(20, 7, "storeSwapOut: " << url());
1820 debugs(20, 7, "storeSwapOut: store_status = " << storeStatusStr
[store_status
]);
1822 if (EBIT_TEST(flags
, ENTRY_ABORTED
)) {
1823 assert(EBIT_TEST(flags
, RELEASE_REQUEST
));
1828 if (EBIT_TEST(flags
, ENTRY_SPECIAL
)) {
1829 debugs(20, 3, "storeSwapOut: " << url() << " SPECIAL");
1837 StoreEntry::trimMemory()
1841 * Bug #1943. We must not let go any data for IN_MEMORY
1842 * objects. We have to wait until the mem_status changes.
1844 if (mem_status
== IN_MEMORY
)
1847 if (!swapOutAble()) {
1848 if (mem_obj
->policyLowestOffsetToKeep(0) == 0) {
1853 * Its not swap-able, and we're about to delete a chunk,
1854 * so we must make it PRIVATE. This is tricky/ugly because
1855 * for the most part, we treat swapable == cachable here.
1858 mem_obj
->trimUnSwappable ();
1860 mem_obj
->trimSwappable ();
1865 StoreEntry::modifiedSince(HttpRequest
* request
) const
1868 time_t mod_time
= lastmod
;
1871 mod_time
= timestamp
;
1873 debugs(88, 3, "modifiedSince: '" << url() << "'");
1875 debugs(88, 3, "modifiedSince: mod_time = " << mod_time
);
1880 /* Find size of the object */
1881 object_length
= getReply()->content_length
;
1883 if (object_length
< 0)
1884 object_length
= contentLen();
1886 if (mod_time
> request
->ims
) {
1887 debugs(88, 3, "--> YES: entry newer than client");
1889 } else if (mod_time
< request
->ims
) {
1890 debugs(88, 3, "--> NO: entry older than client");
1892 } else if (request
->imslen
< 0) {
1893 debugs(88, 3, "--> NO: same LMT, no client length");
1895 } else if (request
->imslen
== object_length
) {
1896 debugs(88, 3, "--> NO: same LMT, same length");
1899 debugs(88, 3, "--> YES: same LMT, different length");
1905 StoreEntry::hasIfMatchEtag(const HttpRequest
&request
) const
1907 const String reqETags
= request
.header
.getList(HDR_IF_MATCH
);
1908 return hasOneOfEtags(reqETags
, false);
1912 StoreEntry::hasIfNoneMatchEtag(const HttpRequest
&request
) const
1914 const String reqETags
= request
.header
.getList(HDR_IF_NONE_MATCH
);
1915 // weak comparison is allowed only for HEAD or full-body GET requests
1916 const bool allowWeakMatch
= !request
.flags
.range
&&
1917 (request
.method
== METHOD_GET
|| request
.method
== METHOD_HEAD
);
1918 return hasOneOfEtags(reqETags
, allowWeakMatch
);
1921 /// whether at least one of the request ETags matches entity ETag
1923 StoreEntry::hasOneOfEtags(const String
&reqETags
, const bool allowWeakMatch
) const
1925 const ETag repETag
= getReply()->header
.getETag(HDR_ETAG
);
1927 return strListIsMember(&reqETags
, "*", ',');
1929 bool matched
= false;
1930 const char *pos
= NULL
;
1933 while (!matched
&& strListGetItem(&reqETags
, ',', &item
, &ilen
, &pos
)) {
1934 if (!strncmp(item
, "*", ilen
))
1938 str
.append(item
, ilen
);
1940 if (etagParseInit(&reqETag
, str
.termedBuf())) {
1941 matched
= allowWeakMatch
? etagIsWeakEqual(repETag
, reqETag
) :
1942 etagIsStrongEqual(repETag
, reqETag
);
1950 StoreEntry::store() const
1952 assert(0 <= swap_dirn
&& swap_dirn
< Config
.cacheSwap
.n_configured
);
1953 return INDEXSD(swap_dirn
);
1957 StoreEntry::unlink()
1959 store()->unlink(*this);
1963 * return true if the entry is in a state where
1964 * it can accept more data (ie with write() method)
1967 StoreEntry::isAccepting() const
1969 if (STORE_PENDING
!= store_status
)
1972 if (EBIT_TEST(flags
, ENTRY_ABORTED
))
1978 /* NullStoreEntry */
1980 NullStoreEntry
NullStoreEntry::_instance
;
1983 NullStoreEntry::getInstance()
1989 NullStoreEntry::getMD5Text() const
1995 NullStoreEntry::operator delete(void*)
1997 fatal ("Attempt to delete NullStoreEntry\n");
2001 NullStoreEntry::getSerialisedMetaData()
2007 #include "Store.cci"