14#include "AUI/Common/AString.h"
15#include "AUI/Common/AMap.h"
16#include "AUI/Common/SharedPtr.h"
17#include "AUI/Thread/AMutex.h"
19template<
typename T,
typename Container,
typename K = AString>
26 virtual _<T> load(
const K& key) = 0;
28 virtual bool isShouldBeCached(
const K& key,
const _<T>& image) {
34 static _<T> get(
const K& key) {
35 Cache& i = Container::inst();
37 std::unique_lock lock(i.mSync);
38 if (
auto i = Container::inst().mContainer.contains(key)) {
42 auto value = i.load(key);
43 if (i.isShouldBeCached(key, value)) {
49 static void put(
const K& key,
_<T> value) {
50 std::unique_lock lock(Container::inst().mSync);
51 Container::inst().mContainer[key] = value;
54 static void cleanup() {
55 std::unique_lock lock(Container::inst().mSync);
56 Container::inst().mContainer.clear();
A std::map with AUI extensions.
Definition: AMap.h:218
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Basic syscall-based synchronization primitive.
Definition: AMutex.h:33