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.



25
26
27
28
# File 'lib/gitlab/markdown_cache/redis/store.rb', line 25

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
# File 'lib/gitlab/markdown_cache/redis/store.rb', line 9

def self.bulk_read(subjects)
  results = {}

  Gitlab::Redis::Cache.with do |r|
    Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do
      Gitlab::Redis::CrossSlot::Pipeline.new(r).pipelined do |pipeline|
        subjects.each do |subject|
          results[subject.cache_key] = new(subject).read(pipeline)
        end
      end
    end
  end

  results
end

Instance Method Details

#loaded?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/gitlab/markdown_cache/redis/store.rb', line 51

def loaded?
  @loaded
end

#read(pipeline = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gitlab/markdown_cache/redis/store.rb', line 39

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



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

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