Class: FastCache::BasicRouter
- Inherits:
-
Object
- Object
- FastCache::BasicRouter
- Defined in:
- lib/fastcache/routing/basic_router.rb
Instance Attribute Summary collapse
-
#bucket_delegate ⇒ Object
readonly
Returns the value of attribute bucket_delegate.
-
#hash_delegate ⇒ Object
readonly
Returns the value of attribute hash_delegate.
Instance Method Summary collapse
- #each(&b) ⇒ Object
-
#initialize(nodes, bucket_class = FastCache::ModulusBucket, hash_class = FastCache::CRC32) ⇒ BasicRouter
constructor
A new instance of BasicRouter.
- #route(key, &b) ⇒ Object
Constructor Details
#initialize(nodes, bucket_class = FastCache::ModulusBucket, hash_class = FastCache::CRC32) ⇒ BasicRouter
Returns a new instance of BasicRouter.
5 6 7 8 9 |
# File 'lib/fastcache/routing/basic_router.rb', line 5 def initialize(nodes, bucket_class = FastCache::ModulusBucket, hash_class = FastCache::CRC32) @nodes = nodes @bucket_delegate = bucket_class.new(nodes) @hash_delegate = hash_class end |
Instance Attribute Details
#bucket_delegate ⇒ Object (readonly)
Returns the value of attribute bucket_delegate.
3 4 5 |
# File 'lib/fastcache/routing/basic_router.rb', line 3 def bucket_delegate @bucket_delegate end |
#hash_delegate ⇒ Object (readonly)
Returns the value of attribute hash_delegate.
3 4 5 |
# File 'lib/fastcache/routing/basic_router.rb', line 3 def hash_delegate @hash_delegate end |
Instance Method Details
#each(&b) ⇒ Object
11 12 13 |
# File 'lib/fastcache/routing/basic_router.rb', line 11 def each(&b) @nodes.each(&b) end |
#route(key, &b) ⇒ Object
15 16 17 18 |
# File 'lib/fastcache/routing/basic_router.rb', line 15 def route(key, &b) digest = @hash_delegate.new(key.to_s).digest @bucket_delegate.select(digest.unpack('N').first, &b) end |