Skip to content

Commit

Permalink
Fixes #36329: Read UI notification cache as JSON
Browse files Browse the repository at this point in the history
The UI notification data is cached as JSON and when retrieved needs
to also be JSON or else a marshalling error is thrown.
  • Loading branch information
ehelms committed Aug 4, 2023
1 parent 7c41286 commit 063eec8
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions app/services/ui_notifications/cache_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@ def initialize(user_id = User.current.try(:id))
@user_id = user_id
end

# JSON Payload
def payload
result = cache.read(cache_key)
if result
logger.debug("Cache Hit: notification, reading cache for #{cache_key}")
return result
cache.fetch(cache_key, raw: true, expires_in: cache_expiry) do
{ notifications: notifications }.to_json
end

result = { notifications: notifications }.to_json

logger.debug("Cache Miss: notification, writing cache for #{cache_key}")
cache.write(cache_key, result, { raw: true, expires_in: cache_expiry })

result
end

def clear
Expand Down

0 comments on commit 063eec8

Please sign in to comment.