1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
10 #include "rocksdb/cache.h"
12 #include "cache/lru_cache.h"
13 #include "rocksdb/utilities/options_type.h"
14 #include "util/string_util.h"
16 namespace ROCKSDB_NAMESPACE
{
18 static std::unordered_map
<std::string
, OptionTypeInfo
>
19 lru_cache_options_type_info
= {
21 {offsetof(struct LRUCacheOptions
, capacity
), OptionType::kSizeT
,
22 OptionVerificationType::kNormal
, OptionTypeFlags::kMutable
}},
24 {offsetof(struct LRUCacheOptions
, num_shard_bits
), OptionType::kInt
,
25 OptionVerificationType::kNormal
, OptionTypeFlags::kMutable
}},
26 {"strict_capacity_limit",
27 {offsetof(struct LRUCacheOptions
, strict_capacity_limit
),
28 OptionType::kBoolean
, OptionVerificationType::kNormal
,
29 OptionTypeFlags::kMutable
}},
30 {"high_pri_pool_ratio",
31 {offsetof(struct LRUCacheOptions
, high_pri_pool_ratio
),
32 OptionType::kDouble
, OptionVerificationType::kNormal
,
33 OptionTypeFlags::kMutable
}},
35 #endif // ROCKSDB_LITE
37 Status
Cache::CreateFromString(const ConfigOptions
& config_options
,
38 const std::string
& value
,
39 std::shared_ptr
<Cache
>* result
) {
41 std::shared_ptr
<Cache
> cache
;
42 if (value
.find('=') == std::string::npos
) {
43 cache
= NewLRUCache(ParseSizeT(value
));
46 LRUCacheOptions cache_opts
;
47 status
= OptionTypeInfo::ParseStruct(
48 config_options
, "", &lru_cache_options_type_info
, "", value
,
49 reinterpret_cast<char*>(&cache_opts
));
51 cache
= NewLRUCache(cache_opts
);
55 status
= Status::NotSupported("Cannot load cache in LITE mode ", value
);
56 #endif //! ROCKSDB_LITE
63 } // namespace ROCKSDB_NAMESPACE