Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pooza committed Sep 30, 2021
1 parent 3c5f223 commit b1fc795
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 13 additions & 7 deletions app/lib/mulukhiya/renderer/rss20_feed_renderer.rb
Expand Up @@ -17,25 +17,31 @@ def cache
command.exec
raise command.stderr unless command.status.zero?
self.entries = JSON.parse(command.stdout)
clear
storage[command] = to_s
storage[command] = render(update: true)
end

alias save cache

def clear
storage[command] = nil
storage.del(command)
end

def to_s
return storage[command] if storage[command].present? rescue super
return super
def render(params = {})
return feed.to_s if params[:update]
return feed.to_s unless storage.key?(command)
return storage[command]
rescue => e
logger.error(error: e)
return feed.to_s
end

alias to_s render

private

def fetch_image(uri)
return storage[uri] if storage[uri].present?
return nil unless uri
return storage[uri] if storage.key?(uri)
return storage[uri] = super
rescue => e
logger.error(error: e)
Expand Down
6 changes: 6 additions & 0 deletions app/lib/mulukhiya/storage/render_storage.rb
Expand Up @@ -12,6 +12,12 @@ def set(command, value)
setex(command, ttl, value)
end

def key?(key)
return keys(create_key(key)).present?
end

alias exist? key?

def setex(command, ttl, value)
if value.is_a?(Enumerable)
super(command, ttl, value.to_json)
Expand Down

0 comments on commit b1fc795

Please sign in to comment.