]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/auth/CredentialsCache.h
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_SRC_AUTH_CREDENTIALSCACHE_H
10 #define SQUID_SRC_AUTH_CREDENTIALSCACHE_H
12 #include "auth/User.h"
14 #include "sbuf/Algorithms.h"
16 #include <unordered_map>
20 /// Cache of Auth::User credentials, keyed by Auth::User::userKey
21 class CredentialsCache
23 CBDATA_CLASS(CredentialsCache
);
26 explicit CredentialsCache(const char *name
, const char * const eventName
);
28 ~CredentialsCache() = default;
29 CredentialsCache(const CredentialsCache
&) = delete;
30 CredentialsCache
& operator=(const CredentialsCache
&) = delete;
32 /// \returns a pointer to cached credentials, or nil if none found
33 Auth::User::Pointer
lookup(const SBuf
&userKey
) const;
35 /// add an user to the cache with the provided key
36 void insert(const SBuf
&userKey
, Auth::User::Pointer anAuth_user
);
39 void reset() { store_
.clear(); }
41 /// \returns number of cached usernames
42 size_t size() const { return store_
.size(); }
44 /** periodic cleanup function, removes timed-out entries
46 * Must be static to support EVH interface. Argument will be this
48 static void Cleanup(void *);
50 /// cache garbage collection, removes timed-out entries
54 * Cleanup cache data after a reconfiguration has occured.
55 * Similar to cleanup() but also flushes stale config dependent
56 * state from retained entries.
58 void doConfigChangeCleanup();
60 /// \returns alphanumerically sorted list of usernames
61 std::vector
<Auth::User::Pointer
> sortedUsersList() const;
64 void scheduleCleanup();
66 /// whether a cleanup (garbage collection) event has been scheduled
69 /// key is User::userKey(), mapped value is User::Pointer
70 typedef std::unordered_map
<SBuf
, Auth::User::Pointer
> StoreType
;
73 // c-string raw pointer used as event name
74 const char * const cacheCleanupEventName
;
77 } /* namespace Auth */
79 #endif /* SQUID_SRC_AUTH_CREDENTIALSCACHE_H */