@@ -73,43 +73,36 @@ class read_optimized_lru_cache
7373 * @returns Returns the value to which the specified key is cached,
7474 * or default value if this cache contains no mapping for the key.
7575 */
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)
7877 {
7978 const auto existing_value = get (key);
80- return ( existing_value != nullptr ) ? existing_value : default_value;
79+ return existing_value ? * existing_value : default_value;
8180 }
8281
8382 /* *
8483 * @param key the key of the cache entry
8584 * 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.
8786 * @returns Returns the value to which the specified key is cached
8887 */
89- std::shared_ptr <V> get (const K& key)
88+ boost::optional <V> get (const K& key)
9089 {
9190 auto value_from_cache = cache_.get (key);
9291 if (value_from_cache == nullptr ) {
93- return nullptr ;
92+ return boost::none ;
9493 }
9594 value_from_cache->touch ();
96- return std::make_shared< int32_t > (value_from_cache->value_ );
95+ return boost::make_optional (value_from_cache->value_ );
9796 }
9897
9998 /* *
10099 * @param key the key of the cache entry
101100 * @param value the value of the cache entry
102- * @throws exception::illegal_argument if the value equals to nullptr
103101 */
104- void put (const K& key, const std::shared_ptr<V> & value)
102+ void put (const K& key, const V & value)
105103 {
106- if (value == nullptr ) {
107- BOOST_THROW_EXCEPTION (client::exception::illegal_argument (
108- " Null values are disallowed" ));
109- }
110-
111104 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));
113106 if (old_value == nullptr && cache_.size () > cleanup_threshold_) {
114107 do_cleanup ();
115108 }
@@ -130,15 +123,15 @@ class read_optimized_lru_cache
130123 {
131124 public:
132125 const T value_;
133- int64_t timestamp_;
126+ std::atomic< int64_t > timestamp_;
134127
135128 value_and_timestamp (T value)
136129 : value_(value)
137130 {
138131 touch ();
139132 }
140133
141- void touch () { timestamp_ = util::current_time_nanos (); }
134+ void touch () { timestamp_. store ( util::current_time_nanos () ); }
142135 };
143136
144137 util::SynchronizedMap<K, value_and_timestamp<V>> cache_;
0 commit comments