#include "squid.h"
#include "acl/Gadgets.h"
#include "auth/CredentialsCache.h"
+#include "base/RunnersRegistry.h"
#include "Debug.h"
#include "event.h"
#include "SquidConfig.h"
namespace Auth {
+class CredentialCacheRr : public RegisteredRunner
+{
+public:
+ explicit CredentialCacheRr(const char *n, CredentialsCache * const c) :
+ name(n),
+ whichCache(c)
+ {}
+
+ virtual ~CredentialCacheRr() {
+ debugs(29, 5, "Terminating username cache: " << name);
+ // invalidate the CBDATA reference.
+ // causes Auth::*::User::Cache() to produce nil / invalid pointer
+ delete whichCache.get();
+ }
+
+ virtual void endingShutdown() override {
+ debugs(29, 5, "Clearing username cache: " << name);
+ whichCache->reset();
+ }
+
+ virtual void syncConfig() override {
+ if (!whichCache.valid())
+ return;
+
+ debugs(29, 5, "Reconfiguring username cache: " << name);
+ whichCache->doConfigChangeCleanup();
+ }
+
+private:
+ /// name of the cache being managed, for logs
+ const char *name;
+
+ /// reference to the scheme cache which is being managed
+ CbcPointer<CredentialsCache> whichCache;
+};
+
CBDATA_CLASS_INIT(CredentialsCache);
CredentialsCache::CredentialsCache(const char *name) :
gcScheduled_(false),
- cachename(name),
cacheCleanupEventName("User cache cleanup: ")
{
debugs(29, 5, "initializing " << name << " username cache");
cacheCleanupEventName.append(name);
- RegisterRunner(this);
+ RegisterRunner(new Auth::CredentialCacheRr(name, this));
}
Auth::User::Pointer
}
void
-CredentialsCache::endingShutdown()
-{
- debugs(29, 5, "Shutting down username cache " << cachename);
- eventDelete(&CredentialsCache::Cleanup, this);
- reset();
-}
-
-void
-CredentialsCache::syncConfig()
+CredentialsCache::doConfigChangeCleanup()
{
- debugs(29, 5, "Reconfiguring username cache " << cachename);
+ // purge expired entries entirely
+ cleanup();
+ // purge the ACL match data stored in the credentials
for (auto i : store_) {
aclCacheMatchFlush(&i.second->proxy_match_cache);
}
#define SQUID_SRC_AUTH_CREDENTIALSCACHE_H
#include "auth/User.h"
-#include "base/RunnersRegistry.h"
#include "cbdata.h"
#include "SBufAlgos.h"
namespace Auth {
/// Cache of Auth::User credentials, keyed by Auth::User::userKey
-class CredentialsCache : public RegisteredRunner
+class CredentialsCache
{
private:
CBDATA_CLASS(CredentialsCache);
/// cache garbage collection, removes timed-out entries
void cleanup();
+ /**
+ * Cleanup cache data after a reconfiguration has occured.
+ * Similar to cleanup() but also flushes stale config dependent
+ * state from retained entries.
+ */
+ void doConfigChangeCleanup();
+
/// obtain alphanumerically sorted list of usernames
std::vector<Auth::User::Pointer> sortedUsersList() const;
- /* RegisteredRunner API */
- virtual void endingShutdown() override;
- virtual void syncConfig() override;
-
private:
void scheduleCleanup();
StoreType store_;
- // for logs, events etc.
- const char *cachename;
-
// c_str() raw pointer is used in event. std::string must not reallocate
// after ctor and until shutdown
// must be unique