mondrian_redis_segment_cache 0.0.4-java → 0.0.5-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mondrian_redis_segment_cache/cache.rb +61 -20
- data/lib/mondrian_redis_segment_cache/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f9d1865c577a8c64f5d69abb17c1e20f85f26a6
|
4
|
+
data.tar.gz: fd0c08ed86a8d88a0843523fba32cb7f316e1ff2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9412cfff753f5ff105ad6e89a2e0232c9253fa5a20bd182f031f88acaa30424b5b1a23d653134436cb2449a65f87d98e654d2041962fb9dcd28578c244f4c14
|
7
|
+
data.tar.gz: b1ab22bd6e88bb7b440fbe4acd5323607ab6ca5afcef2c5686560f62f1f498a21059253b4abc8b8e113a87de47debfffd33215dd05011839051e225099771596
|
@@ -6,20 +6,22 @@ module MondrianRedisSegmentCache
|
|
6
6
|
class Cache
|
7
7
|
include Java::MondrianSpi::SegmentCache
|
8
8
|
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :created_listener_connection, :deleted_listener_connection, :listeners, :mondrian_redis, :options
|
10
10
|
|
11
11
|
SEGMENT_HEADERS_SET_KEY = "MONDRIAN_SEGMENT_HEADERS_SET"
|
12
12
|
|
13
13
|
##
|
14
14
|
# Constructor
|
15
15
|
#
|
16
|
-
def initialize(mondrian_redis_connection)
|
16
|
+
def initialize(mondrian_redis_connection, new_options = {})
|
17
17
|
@mondrian_redis = mondrian_redis_connection
|
18
18
|
@created_listener_connection = ::Redis.new(client_options)
|
19
19
|
@deleted_listener_connection = ::Redis.new(client_options)
|
20
|
+
@options = Marshal.load(Marshal.dump(new_options))
|
20
21
|
|
21
22
|
reset_listeners
|
22
23
|
register_for_redis_events
|
24
|
+
reconcile_set_and_keys
|
23
25
|
end
|
24
26
|
|
25
27
|
##
|
@@ -27,6 +29,7 @@ module MondrianRedisSegmentCache
|
|
27
29
|
#
|
28
30
|
def addListener(segment_cache_listener)
|
29
31
|
listeners << segment_cache_listener
|
32
|
+
eager_load_listener(segment_cache_listener)
|
30
33
|
end
|
31
34
|
|
32
35
|
# returns boolean
|
@@ -50,6 +53,13 @@ module MondrianRedisSegmentCache
|
|
50
53
|
@created_event_key ||= "__keyevent@#{client_options[:db]}__:del"
|
51
54
|
end
|
52
55
|
|
56
|
+
def eager_load_listener(listener)
|
57
|
+
segment_headers_base64 = mondrian_redis.smembers(SEGMENT_HEADERS_SET_KEY)
|
58
|
+
segment_headers_base64.each do |segment_header_base64|
|
59
|
+
publish_created_to_listener(segment_header_base64, listener)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
53
63
|
# returns mondrian.spi.SegmentBody
|
54
64
|
# takes mondrian.spi.SegmentHeader
|
55
65
|
def get(segment_header)
|
@@ -79,25 +89,38 @@ module MondrianRedisSegmentCache
|
|
79
89
|
return segment_headers
|
80
90
|
end
|
81
91
|
|
82
|
-
def
|
92
|
+
def publish_created_to_listener(message, listener)
|
83
93
|
segment_header = segment_header_from_base64(message)
|
84
94
|
|
85
95
|
if segment_header
|
86
|
-
|
87
|
-
|
88
|
-
listener.handle(created_event)
|
89
|
-
end
|
96
|
+
created_event = ::MondrianRedisSegmentCache::CreatedEvent.new(segment_header)
|
97
|
+
listener.handle(created_event)
|
90
98
|
end
|
91
99
|
end
|
92
100
|
|
93
|
-
def
|
101
|
+
def publish_created_to_listeners(message)
|
102
|
+
listeners.each do |listener|
|
103
|
+
publish_created_to_listener(message, listener)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def publish_deleted_to_listener(message, listener)
|
94
108
|
segment_header = segment_header_from_base64(message)
|
95
109
|
|
96
110
|
if segment_header
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
111
|
+
deleted_event = ::MondrianRedisSegmentCache::DeletedEvent.new(segment_header)
|
112
|
+
listener.handle(deleted_event)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def publish_deleted_to_listeners(message)
|
117
|
+
listeners.each do |listener|
|
118
|
+
publish_deleted_to_listener(message, listener)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Each server can tell the Set to remove the key as it may be expired
|
122
|
+
if mondrian_redis.sismember(SEGMENT_HEADERS_SET_KEY, message)
|
123
|
+
mondrian_redis.srem(SEGMENT_HEADERS_SET_KEY, message)
|
101
124
|
end
|
102
125
|
end
|
103
126
|
|
@@ -106,9 +129,14 @@ module MondrianRedisSegmentCache
|
|
106
129
|
header_base64 = segment_header_to_base64(segment_header)
|
107
130
|
body_base64 = segment_body_to_base64(segment_body)
|
108
131
|
mondrian_redis.sadd(SEGMENT_HEADERS_SET_KEY, header_base64)
|
109
|
-
|
132
|
+
|
133
|
+
if options[:ttl]
|
134
|
+
set_success = mondrian_redis.set(header_base64, body_base64, :ex => options[:ttl])
|
135
|
+
else
|
136
|
+
set_success = mondrian_redis.set(header_base64, body_base64)
|
137
|
+
end
|
110
138
|
|
111
|
-
return (set_success == "OK" || set_success == true) # weird polymorphic return ?
|
139
|
+
return ("#{set_success}".upcase == "OK" || set_success == true) # weird polymorphic return ?
|
112
140
|
end
|
113
141
|
|
114
142
|
def remove(segment_header)
|
@@ -133,13 +161,15 @@ module MondrianRedisSegmentCache
|
|
133
161
|
end
|
134
162
|
|
135
163
|
def tearDown()
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
164
|
+
if options[:delete_all_on_tear_down]
|
165
|
+
# Remove all of the headers and the set that controls them
|
166
|
+
segment_headers_base64 = mondrian_redis.smembers(SEGMENT_HEADERS_SET_KEY)
|
167
|
+
segment_headers_base64.each do |segment_header_base64|
|
168
|
+
mondrian_redis.del(segment_header_base64)
|
169
|
+
end
|
141
170
|
|
142
|
-
|
171
|
+
mondrian_redis.del(SEGMENT_HEADERS_SET_KEY)
|
172
|
+
end
|
143
173
|
end
|
144
174
|
|
145
175
|
private
|
@@ -160,6 +190,17 @@ module MondrianRedisSegmentCache
|
|
160
190
|
return mondrian_redis.client.options
|
161
191
|
end
|
162
192
|
|
193
|
+
def reconcile_set_and_keys
|
194
|
+
segment_headers_base64 = mondrian_redis.smembers(SEGMENT_HEADERS_SET_KEY)
|
195
|
+
|
196
|
+
segment_headers_base64.each do |segment_header_base64|
|
197
|
+
# Spin through Header Set and remove any keys that are not in redis at all (they may have been deleted while offline)
|
198
|
+
unless mondrian_redis.exists(header_base64)
|
199
|
+
mondrian_redis.srem(SEGMENT_HEADERS_SET_KEY, message)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
163
204
|
def register_for_redis_events
|
164
205
|
return if @listeners_registered
|
165
206
|
|