@@ -73,43 +73,36 @@ class read_optimized_lru_cache
73
73
* @returns Returns the value to which the specified key is cached,
74
74
* or default value if this cache contains no mapping for the key.
75
75
*/
76
- std::shared_ptr<V> get_or_default (const K& key,
77
- const std::shared_ptr<V>& default_value)
76
+ V get_or_default (const K& key, const V& default_value)
78
77
{
79
78
const auto existing_value = get (key);
80
- return ( existing_value != nullptr ) ? existing_value : default_value;
79
+ return existing_value ? * existing_value : default_value;
81
80
}
82
81
83
82
/* *
84
83
* @param key the key of the cache entry
85
84
* Returns the value to which the specified key is cached,
86
- * or {@code null } if this cache contains no mapping for the key.
85
+ * or {@code boost::none } if this cache contains no mapping for the key.
87
86
* @returns Returns the value to which the specified key is cached
88
87
*/
89
- std::shared_ptr <V> get (const K& key)
88
+ boost::optional <V> get (const K& key)
90
89
{
91
90
auto value_from_cache = cache_.get (key);
92
91
if (value_from_cache == nullptr ) {
93
- return nullptr ;
92
+ return boost::none ;
94
93
}
95
94
value_from_cache->touch ();
96
- return std::make_shared< int32_t > (value_from_cache->value_ );
95
+ return boost::make_optional (value_from_cache->value_ );
97
96
}
98
97
99
98
/* *
100
99
* @param key the key of the cache entry
101
100
* @param value the value of the cache entry
102
- * @throws exception::illegal_argument if the value equals to nullptr
103
101
*/
104
- void put (const K& key, const std::shared_ptr<V> & value)
102
+ void put (const K& key, const V & value)
105
103
{
106
- if (value == nullptr ) {
107
- BOOST_THROW_EXCEPTION (client::exception::illegal_argument (
108
- " Null values are disallowed" ));
109
- }
110
-
111
104
auto old_value =
112
- cache_.put (key, std::make_shared<value_and_timestamp<V>>(* value));
105
+ cache_.put (key, std::make_shared<value_and_timestamp<V>>(value));
113
106
if (old_value == nullptr && cache_.size () > cleanup_threshold_) {
114
107
do_cleanup ();
115
108
}
@@ -130,15 +123,15 @@ class read_optimized_lru_cache
130
123
{
131
124
public:
132
125
const T value_;
133
- int64_t timestamp_;
126
+ std::atomic< int64_t > timestamp_;
134
127
135
128
value_and_timestamp (T value)
136
129
: value_(value)
137
130
{
138
131
touch ();
139
132
}
140
133
141
- void touch () { timestamp_ = util::current_time_nanos (); }
134
+ void touch () { timestamp_. store ( util::current_time_nanos () ); }
142
135
};
143
136
144
137
util::SynchronizedMap<K, value_and_timestamp<V>> cache_;
0 commit comments