Skip to content

Commit 52e5f37

Browse files
committed
Renamed Concurrent::Cache to Concurrent::Map.
1 parent 36fd269 commit 52e5f37

15 files changed

+58
-93
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ These classes were originally part of the (deprecated) `thread_safe` gem.
7575

7676
* [Array](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Array.html) A thread-safe subclass of Ruby's standard [Array](http://ruby-doc.org/core-2.2.0/Array.html).
7777
* [Hash](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Hash.html) A thread-safe subclass of Ruby's standard [Hash](http://ruby-doc.org/core-2.2.0/Hash.html).
78-
* [Cache](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Cache.html) A hash-like object that should have much better performance characteristics, especially under high concurrency, than `Concurrent::Hash`.
78+
* [Map](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Map.html) A hash-like object that should have much better performance characteristics, especially under high concurrency, than `Concurrent::Hash`.
7979

8080
#### Thread-safe Value Objects
8181

examples/bench_cache.rb

Lines changed: 0 additions & 35 deletions
This file was deleted.

examples/bench_map.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
#!/usr/bin/env ruby -wU
1+
#!/usr/bin/env ruby
22

3-
require 'benchmark'
4-
require 'concurrent'
3+
require "benchmark"
4+
require "concurrent"
55

66
hash = {}
7-
cache = Concurrent::Map.new
7+
map = Concurrent::Map.new
88

99
ENTRIES = 10_000
1010

1111
ENTRIES.times do |i|
1212
hash[i] = i
13-
cache[i] = i
13+
map[i] = i
1414
end
1515

1616
TESTS = 40_000_000
@@ -22,14 +22,14 @@
2222
end
2323

2424
results.report('Map#[]') do
25-
TESTS.times { cache[key] }
25+
TESTS.times { map[key] }
2626
end
2727

2828
results.report('Hash#each_pair') do
2929
(TESTS / ENTRIES).times { hash.each_pair {|k,v| v} }
3030
end
3131

3232
results.report('Map#each_pair') do
33-
(TESTS / ENTRIES).times { cache.each_pair {|k,v| v} }
33+
(TESTS / ENTRIES).times { map.each_pair {|k,v| v} }
3434
end
3535
end

ext/ConcurrentRubyExtService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.jruby.Ruby;
44
import org.jruby.runtime.load.BasicLibraryService;
5-
import com.concurrent_ruby.ext.JRubyCacheBackendLibrary;
5+
import com.concurrent_ruby.ext.JRubyMapBackendLibrary;
66

77
public class ConcurrentRubyExtService implements BasicLibraryService {
88
public boolean basicLoad(final Ruby runtime) throws IOException {
@@ -11,7 +11,7 @@ public boolean basicLoad(final Ruby runtime) throws IOException {
1111
new com.concurrent_ruby.ext.JavaAtomicFixnumLibrary().load(runtime, false);
1212
new com.concurrent_ruby.ext.JavaSemaphoreLibrary().load(runtime, false);
1313
new com.concurrent_ruby.ext.SynchronizationLibrary().load(runtime, false);
14-
new com.concurrent_ruby.ext.JRubyCacheBackendLibrary().load(runtime, false);
14+
new com.concurrent_ruby.ext.JRubyMapBackendLibrary().load(runtime, false);
1515
return true;
1616
}
1717
}

ext/com/concurrent_ruby/ext/JRubyCacheBackendLibrary.java renamed to ext/com/concurrent_ruby/ext/JRubyMapBackendLibrary.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@
2323
*
2424
* @author thedarkone
2525
*/
26-
public class JRubyCacheBackendLibrary implements Library {
26+
public class JRubyMapBackendLibrary implements Library {
2727
public void load(Ruby runtime, boolean wrap) throws IOException {
2828

2929
RubyModule concurrentMod = runtime.defineModule("Concurrent");
3030
RubyModule thread_safeMod = concurrentMod.defineModuleUnder("ThreadSafe");
31-
RubyClass jrubyRefClass = thread_safeMod.defineClassUnder("JRubyCacheBackend", runtime.getObject(), BACKEND_ALLOCATOR);
31+
RubyClass jrubyRefClass = thread_safeMod.defineClassUnder("JRubyMapBackend", runtime.getObject(), BACKEND_ALLOCATOR);
3232
jrubyRefClass.setAllocator(BACKEND_ALLOCATOR);
33-
jrubyRefClass.defineAnnotatedMethods(JRubyCacheBackend.class);
33+
jrubyRefClass.defineAnnotatedMethods(JRubyMapBackend.class);
3434
}
3535

3636
private static final ObjectAllocator BACKEND_ALLOCATOR = new ObjectAllocator() {
3737
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
38-
return new JRubyCacheBackend(runtime, klazz);
38+
return new JRubyMapBackend(runtime, klazz);
3939
}
4040
};
4141

42-
@JRubyClass(name="JRubyCacheBackend", parent="Object")
43-
public static class JRubyCacheBackend extends RubyObject {
42+
@JRubyClass(name="JRubyMapBackend", parent="Object")
43+
public static class JRubyMapBackend extends RubyObject {
4444
// Defaults used by the CHM
4545
static final int DEFAULT_INITIAL_CAPACITY = 16;
4646
static final float DEFAULT_LOAD_FACTOR = 0.75f;
@@ -65,7 +65,7 @@ private static boolean isCausedBySecurityException(Throwable t) {
6565
return false;
6666
}
6767

68-
public JRubyCacheBackend(Ruby runtime, RubyClass klass) {
68+
public JRubyMapBackend(Ruby runtime, RubyClass klass) {
6969
super(runtime, klass);
7070
}
7171

@@ -228,7 +228,7 @@ public IRubyObject get_or_default(IRubyObject key, IRubyObject defaultValue) {
228228
}
229229

230230
@JRubyMethod(visibility = PRIVATE)
231-
public JRubyCacheBackend initialize_copy(ThreadContext context, IRubyObject other) {
231+
public JRubyMapBackend initialize_copy(ThreadContext context, IRubyObject other) {
232232
map = newCHM();
233233
return this;
234234
}

lib/concurrent.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
require 'concurrent/atom'
1313
require 'concurrent/array'
1414
require 'concurrent/async'
15-
require 'concurrent/cache'
1615
require 'concurrent/dataflow'
1716
require 'concurrent/delay'
1817
require 'concurrent/future'
1918
require 'concurrent/hash'
2019
require 'concurrent/immutable_struct'
2120
require 'concurrent/ivar'
21+
require 'concurrent/map'
2222
require 'concurrent/maybe'
2323
require 'concurrent/mutable_struct'
2424
require 'concurrent/mvar'

lib/concurrent/cache.rb renamed to lib/concurrent/map.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
require 'thread'
22

33
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'
99

1010
# @!visibility private
1111
module ThreadSafe
1212

1313
# @!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
2319
else
24-
MriCacheBackend
20+
warn 'Concurrent::Map: unsupported Ruby engine, using a fully synchronized Concurrent::Map implementation' if $VERBOSE
21+
SynchronizedMapBackend
2522
end
23+
else
24+
MriMapBackend
25+
end
2626
end
2727

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
2929
# 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`
3131
# -- for instance, it does not necessarily retain ordering by insertion time as `Hash`
3232
# 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.
3434
#
3535
# > require 'concurrent'
3636
# >
37-
# > cache = Concurrent::Cache.new
37+
# > map = Concurrent::Map.new
3838

39-
class Cache < ThreadSafe::CacheBackend
39+
class Map < ThreadSafe::MapBackend
4040
def initialize(options = nil, &block)
4141
if options.kind_of?(::Hash)
4242
validate_options_hash!(options)

lib/concurrent/thread_safe.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
require 'concurrent/thread_safe/synchronized_delegator'
33

44
module Concurrent
5-
autoload :Cache, 'concurrent/cache'
6-
autoload :Util, 'concurrent/thread_safe/util'
5+
autoload :Map, 'concurrent/map'
6+
autoload :Util, 'concurrent/thread_safe/util'
77

88
# Various classes within allows for +nil+ values to be stored,
99
# so a special +NULL+ token is required to indicate the "nil-ness".

lib/concurrent/thread_safe/atomic_reference_cache_backend.rb renamed to lib/concurrent/thread_safe/atomic_reference_map_backend.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ module ThreadSafe
183183
# checks.
184184
#
185185
# @!visibility private
186-
class AtomicReferenceCacheBackend
186+
class AtomicReferenceMapBackend
187187

188188
# @!visibility private
189189
class Table < Util::PowerOfTwoTuple

lib/concurrent/thread_safe/mri_cache_backend.rb renamed to lib/concurrent/thread_safe/mri_map_backend.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Concurrent
44
module ThreadSafe
55

66
# @!visibility private
7-
class MriCacheBackend < NonConcurrentCacheBackend
7+
class MriMapBackend < NonConcurrentMapBackend
88

99
# We can get away with a single global write lock (instead of a per-instance
1010
# one) because of the GVL/green threads.

0 commit comments

Comments
 (0)