|
1 | 1 | require 'thread' |
2 | 2 |
|
3 | 3 | module Concurrent |
4 | | - autoload :JRubyCacheBackend, 'concurrent/thread_safe/jruby_cache_backend' |
5 | | - autoload :MriCacheBackend, 'concurrent/thread_safe/mri_cache_backend' |
6 | | - autoload :NonConcurrentCacheBackend, 'concurrent/thread_safe/non_concurrent_cache_backend' |
7 | | - autoload :AtomicReferenceCacheBackend, 'concurrent/thread_safe/atomic_reference_cache_backend' |
8 | | - autoload :SynchronizedCacheBackend, 'concurrent/thread_safe/synchronized_cache_backend' |
| 4 | + autoload :JRubyMapBackend, 'concurrent/thread_safe/jruby_map_backend' |
| 5 | + autoload :MriMapBackend, 'concurrent/thread_safe/mri_map_backend' |
| 6 | + autoload :NonConcurrentMapBackend, 'concurrent/thread_safe/non_concurrent_map_backend' |
| 7 | + autoload :AtomicReferenceMapBackend, 'concurrent/thread_safe/atomic_reference_map_backend' |
| 8 | + autoload :SynchronizedMapBackend, 'concurrent/thread_safe/synchronized_map_backend' |
9 | 9 |
|
10 | 10 | # @!visibility private |
11 | 11 | module ThreadSafe |
12 | 12 |
|
13 | 13 | # @!visibility private |
14 | | - CacheBackend = if defined?(RUBY_ENGINE) |
15 | | - case RUBY_ENGINE |
16 | | - when 'jruby'; JRubyCacheBackend |
17 | | - when 'ruby'; MriCacheBackend |
18 | | - when 'rbx'; AtomicReferenceCacheBackend |
19 | | - else |
20 | | - warn 'Concurrent::Cache: unsupported Ruby engine, using a fully synchronized Concurrent::Cache implementation' if $VERBOSE |
21 | | - SynchronizedCacheBackend |
22 | | - end |
| 14 | + MapBackend = if defined?(RUBY_ENGINE) |
| 15 | + case RUBY_ENGINE |
| 16 | + when 'jruby'; JRubyMapBackend |
| 17 | + when 'ruby'; MriMapBackend |
| 18 | + when 'rbx'; AtomicReferenceMapBackend |
23 | 19 | else |
24 | | - MriCacheBackend |
| 20 | + warn 'Concurrent::Map: unsupported Ruby engine, using a fully synchronized Concurrent::Map implementation' if $VERBOSE |
| 21 | + SynchronizedMapBackend |
25 | 22 | end |
| 23 | + else |
| 24 | + MriMapBackend |
| 25 | + end |
26 | 26 | end |
27 | 27 |
|
28 | | - # `Concurrent::Cache` is a hash-like object and should have much better performance |
| 28 | + # `Concurrent::Map` is a hash-like object and should have much better performance |
29 | 29 | # characteristics, especially under high concurrency, than `Concurrent::Hash`. |
30 | | - # However, `Concurrent::Cache `is not strictly semantically equivalent to a ruby `Hash` |
| 30 | + # However, `Concurrent::Map `is not strictly semantically equivalent to a ruby `Hash` |
31 | 31 | # -- for instance, it does not necessarily retain ordering by insertion time as `Hash` |
32 | 32 | # does. For most uses it should do fine though, and we recommend you consider |
33 | | - # `Concurrent::Cache` instead of `Concurrent::Hash` for your concurrency-safe hash needs. |
| 33 | + # `Concurrent::Map` instead of `Concurrent::Hash` for your concurrency-safe hash needs. |
34 | 34 | # |
35 | 35 | # > require 'concurrent' |
36 | 36 | # > |
37 | | - # > cache = Concurrent::Cache.new |
| 37 | + # > map = Concurrent::Map.new |
38 | 38 |
|
39 | | - class Cache < ThreadSafe::CacheBackend |
| 39 | + class Map < ThreadSafe::MapBackend |
40 | 40 | def initialize(options = nil, &block) |
41 | 41 | if options.kind_of?(::Hash) |
42 | 42 | validate_options_hash!(options) |
|
0 commit comments