/*
- * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#define SQUID_SRC_AUTH_CREDENTIALSCACHE_H
#include "auth/User.h"
-#include "base/RunnersRegistry.h"
#include "cbdata.h"
-#include "SBufAlgos.h"
+#include "sbuf/Algorithms.h"
#include <unordered_map>
namespace Auth {
/// Cache of Auth::User credentials, keyed by Auth::User::userKey
-class CredentialsCache : public RegisteredRunner
+class CredentialsCache
{
-private:
CBDATA_CLASS(CredentialsCache);
- /// key is User::userKey(), mapped value is User::Pointer
- typedef std::unordered_map<SBuf, Auth::User::Pointer> StoreType;
-
public:
- CredentialsCache() = delete;
- explicit CredentialsCache(const char *name);
+ explicit CredentialsCache(const char *name, const char * const eventName);
~CredentialsCache() = default;
- CredentialsCache(const CredentialsCache& ) = delete;
+ CredentialsCache(const CredentialsCache&) = delete;
CredentialsCache& operator=(const CredentialsCache&) = delete;
- /// obtain pointer to user if present, or Pointer(nullptr) if not
/// \returns a pointer to cached credentials, or nil if none found
Auth::User::Pointer lookup(const SBuf &userKey) const;
- /// add an user to the cache
- void insert(Auth::User::Pointer anAuth_user);
+ /// add an user to the cache with the provided key
+ void insert(const SBuf &userKey, Auth::User::Pointer anAuth_user);
/// clear cache
void reset() { store_.clear(); }
- /// extract number of cached usernames
+ /// \returns number of cached usernames
size_t size() const { return store_.size(); }
/** periodic cleanup function, removes timed-out entries
/// cache garbage collection, removes timed-out entries
void cleanup();
- /** obtain sorted list of usernames
- *
+ /**
+ * Cleanup cache data after a reconfiguration has occurred.
+ * Similar to cleanup() but also flushes stale config dependent
+ * state from retained entries.
*/
- std::vector<Auth::User::Pointer> sortedUsersList() const;
+ void doConfigChangeCleanup();
- /* RegisteredRunner API */
- virtual void endingShutdown() override;
- virtual void syncConfig() override;
+ /// \returns alphanumerically sorted list of usernames
+ std::vector<Auth::User::Pointer> sortedUsersList() const;
private:
void scheduleCleanup();
- /// whether a GC event has been scheduled
+ /// whether a cleanup (garbage collection) event has been scheduled
bool gcScheduled_;
+ /// key is User::userKey(), mapped value is User::Pointer
+ typedef std::unordered_map<SBuf, Auth::User::Pointer> StoreType;
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
- std::string cacheCleanupEventName;
+ // c-string raw pointer used as event name
+ const char * const cacheCleanupEventName;
};
} /* namespace Auth */