aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/complete/name/cache/cache.h
blob: 357989edc50da21b316b8c8d6609a791122a7e9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include "byte_size.h"

#include <library/cpp/threading/future/future.h>

#include <util/generic/ptr.h>
#include <util/datetime/base.h>

namespace NSQLComplete {

    namespace NPrivate {

        template <class T>
        concept CHashable = requires(const T& x) {
            { THash<T>()(x) } -> std::convertible_to<std::size_t>;
        };

        template <class T>
        concept CCacheKey = std::regular<T> && CHashable<T> && CByteSized<T>;

        template <class T>
        concept CCacheValue = std::copyable<T> && CByteSized<T>;

    }; // namespace NPrivate

    template <NPrivate::CCacheKey TKey, NPrivate::CCacheValue TValue>
    class ICache: public TThrRefBase {
    public:
        using TPtr = TIntrusivePtr<ICache>;

        struct TEntry {
            TMaybe<TValue> Value = Nothing();
            bool IsExpired = true;
        };

        virtual ~ICache() = default;
        virtual NThreading::TFuture<TEntry> Get(const TKey& key) const = 0;
        virtual NThreading::TFuture<void> Update(const TKey& key, TValue value) const = 0;
    };

} // namespace NSQLComplete