1 /*
2  * Copyright (C) 1996-2021 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_STORE_STORAGE_H
10 #define SQUID_STORE_STORAGE_H
11 
12 #include "base/RefCount.h"
13 #include "http/RequestMethod.h"
14 #include "store/forward.h"
15 #include "store_key_md5.h"
16 
17 class StoreInfoStats;
18 
19 namespace Store {
20 
21 /// A "response storage" abstraction.
22 /// This API is shared among Controller and Controlled classes.
23 class Storage: public RefCountable
24 {
25 public:
~Storage()26     virtual ~Storage() {}
27 
28     /// create system resources needed for this store to operate in the future
29     virtual void create() = 0;
30 
31     /// Start preparing the store for use. To check readiness, callers should
32     /// use readable() and writable() methods.
33     virtual void init() = 0;
34 
35     /**
36      * The maximum size the store will support in normal use. Inaccuracy is
37      * permitted, but may throw estimates for memory etc out of whack.
38      */
39     virtual uint64_t maxSize() const = 0;
40 
41     /// the minimum size the store will shrink to via normal housekeeping
42     virtual uint64_t minSize() const = 0;
43 
44     /// current size
45     virtual uint64_t currentSize() const = 0;
46 
47     /// the total number of objects stored right now
48     virtual uint64_t currentCount() const = 0;
49 
50     /// the maximum size of a storable object; -1 if unlimited
51     virtual int64_t maxObjectSize() const = 0;
52 
53     /// collect statistics
54     virtual void getStats(StoreInfoStats &stats) const = 0;
55 
56     /**
57      * Output stats to the provided store entry.
58      \todo make these calls asynchronous
59      */
60     virtual void stat(StoreEntry &e) const = 0;
61 
62     /// Prevent new get() calls from returning the matching entry.
63     /// If the matching entry is unused, it may be removed from the store now.
64     /// The store entry is matched using either `e` attachment info or `e.key`.
65     virtual void evictCached(StoreEntry &e) = 0;
66 
67     /// An evictCached() equivalent for callers that did not get() a StoreEntry.
68     /// Callers with StoreEntry objects must use evictCached() instead.
69     virtual void evictIfFound(const cache_key *) = 0;
70 
71     /// called once every main loop iteration; TODO: Move to UFS code.
callback()72     virtual int callback() { return 0; }
73 
74     /// perform regular periodic maintenance; TODO: move to UFSSwapDir::Maintain
75     virtual void maintain() = 0;
76 
77     /// prepare for shutdown
sync()78     virtual void sync() {}
79 
80     /// whether this storage is capable of serving multiple workers;
81     /// a true result does not imply [lack of] non-SMP support because
82     /// [only] some SMP-aware storages also support non-SMP configss
83     virtual bool smpAware() const = 0;
84 };
85 
86 } // namespace Store
87 
88 #endif /* SQUID_STORE_STORAGE_H */
89 
90