Class: Gitlab::MarkdownCache::Redis::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/markdown_cache/redis/store.rb

Constant Summary collapse

EXPIRES_IN =
1.day

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject) ⇒ Store

Returns a new instance of Store.



30
31
32
33
# File 'lib/gitlab/markdown_cache/redis/store.rb', line 30

def initialize(subject)
  @subject = subject
  @loaded = false
end

Class Method Details

.bulk_read(subjects) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/markdown_cache/redis/store.rb', line 9

def self.bulk_read(subjects)
  results = {}

  data = Gitlab::Redis::Cache.with do |r|
    Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do
      r.pipelined do |pipeline|
        subjects.each do |subject|
          new(subject).read(pipeline)
        end
      end
    end
  end

  # enumerate data
  data.each_with_index do |elem, idx|
    results[subjects[idx].cache_key] = elem
  end

  results
end

Instance Method Details

#loaded?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/gitlab/markdown_cache/redis/store.rb', line 56

def loaded?
  @loaded
end

#read(pipeline = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gitlab/markdown_cache/redis/store.rb', line 44

def read(pipeline = nil)
  @loaded = true

  if pipeline
    pipeline.mapped_hmget(markdown_cache_key, *fields)
  else
    with_redis do |r|
      r.mapped_hmget(markdown_cache_key, *fields)
    end
  end
end

#save(updates) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/gitlab/markdown_cache/redis/store.rb', line 35

def save(updates)
  @loaded = false

  with_redis do |r|
    r.mapped_hmset(markdown_cache_key, updates)
    r.expire(markdown_cache_key, EXPIRES_IN)
  end
end