# Cache implementation

Use readthis gem as a Cache implemetation.

https://github.com/sorentwo/readthis/blob/master/lib/readthis/cache.rb

# Call raw Redis commands

"Readthis" gem supports running arbitraty Redis commands

#TODO code example
1

# Cache Repositories

class CacheRepository

  include ::AutoInject['client.cache']

  def create_with_id(id, value)
    cache.write(key(id), value)
    value
  end

  ...

end

class PostCacheRepository < CacheRepository

  def create(params)
    post = PostRepository.new.create(params)
    create_with_id("posts:#{post.id}", params)
  end

  ...

end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23