Class: SolidCacheDashboard::Decorators::CacheEntryDecorator
- Inherits:
-
Object
- Object
- SolidCacheDashboard::Decorators::CacheEntryDecorator
- Defined in:
- lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb
Instance Method Summary collapse
- #byte_size ⇒ Object
- #created_at ⇒ Object
- #created_at_ago ⇒ Object
- #encrypted? ⇒ Boolean
- #encryption_status ⇒ Object
- #estimated_row_overhead ⇒ Object
- #expires_at ⇒ Object
- #expires_in ⇒ Object
- #human_byte_size ⇒ Object
-
#initialize(entry) ⇒ CacheEntryDecorator
constructor
A new instance of CacheEntryDecorator.
- #key ⇒ Object
- #key_hash ⇒ Object
- #key_size ⇒ Object
- #overhead_percentage ⇒ Object
- #overhead_size ⇒ Object
- #status ⇒ Object
- #status_badge ⇒ Object
- #time_ago_in_words(from_time, to_time = Time.now) ⇒ Object
- #total_lifetime ⇒ Object
- #value ⇒ Object
- #value_size ⇒ Object
Constructor Details
#initialize(entry) ⇒ CacheEntryDecorator
Returns a new instance of CacheEntryDecorator.
4 5 6 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 4 def initialize(entry) @entry = entry end |
Instance Method Details
#byte_size ⇒ Object
24 25 26 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 24 def byte_size @entry.byte_size end |
#created_at ⇒ Object
32 33 34 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 32 def created_at @entry.created_at end |
#created_at_ago ⇒ Object
36 37 38 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 36 def created_at_ago time_ago_in_words(created_at, Time.now) end |
#encrypted? ⇒ Boolean
66 67 68 69 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 66 def encrypted? return false unless defined?(SolidCache.configuration) SolidCache.configuration.encrypt? end |
#encryption_status ⇒ Object
71 72 73 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 71 def encryption_status encrypted? ? "Encrypted" : "Not encrypted" end |
#estimated_row_overhead ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 75 def estimated_row_overhead if encrypted? SolidCache::Entry::ESTIMATED_ROW_OVERHEAD + SolidCache::Entry::ESTIMATED_ENCRYPTION_OVERHEAD else SolidCache::Entry::ESTIMATED_ROW_OVERHEAD end rescue NameError 140 # fallback to default ESTIMATED_ROW_OVERHEAD end |
#expires_at ⇒ Object
51 52 53 54 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 51 def expires_at return unless @entry.respond_to?(:expires_at) @entry.expires_at end |
#expires_in ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 56 def expires_in return unless expires_at if expires_at <= Time.now "Expired #{time_ago_in_words(expires_at, Time.now)}" else time_ago_in_words(Time.now, expires_at) end end |
#human_byte_size ⇒ Object
28 29 30 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 28 def human_byte_size ActiveSupport::NumberHelper.number_to_human_size(byte_size) end |
#key ⇒ Object
12 13 14 15 16 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 12 def key @entry.key rescue key_hash end |
#key_hash ⇒ Object
8 9 10 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 8 def key_hash @entry.key_hash end |
#key_size ⇒ Object
85 86 87 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 85 def key_size @entry.key.to_s.bytesize end |
#overhead_percentage ⇒ Object
97 98 99 100 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 97 def overhead_percentage return 0 if byte_size == 0 (overhead_size.to_f / byte_size * 100).round(1) end |
#overhead_size ⇒ Object
93 94 95 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 93 def overhead_size byte_size - key_size - value_size end |
#status ⇒ Object
40 41 42 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 40 def status expires_at.present? && expires_at <= Time.now ? SolidCacheDashboard::CacheEntry::EXPIRED : SolidCacheDashboard::CacheEntry::ACTIVE end |
#status_badge ⇒ Object
44 45 46 47 48 49 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 44 def status_badge status_text = status.to_s.capitalize color = SolidCacheDashboard::CacheEntry.status_color(status) "<span class='inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-#{color}-100 dark:bg-#{color}-800 text-#{color}-800 dark:text-#{color}-100'>#{status_text}</span>".html_safe end |
#time_ago_in_words(from_time, to_time = Time.now) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 119 def time_ago_in_words(from_time, to_time = Time.now) distance_in_seconds = (to_time - from_time).abs.round suffix = to_time > from_time ? "ago" : "from now" time_words = case distance_in_seconds when 0..59 "#{distance_in_seconds} seconds" when 60..3599 "#{(distance_in_seconds / 60).round} minutes" when 3600..86399 "#{(distance_in_seconds / 3600).round} hours" else "#{(distance_in_seconds / 86400).round} days" end "#{time_words} #{suffix}" end |
#total_lifetime ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 102 def total_lifetime return nil unless expires_at && created_at distance_in_seconds = (expires_at - created_at).round case distance_in_seconds when 0..59 "#{distance_in_seconds} seconds" when 60..3599 "#{(distance_in_seconds / 60).round} minutes" when 3600..86399 "#{(distance_in_seconds / 3600).round} hours" else "#{(distance_in_seconds / 86400).round} days" end end |
#value ⇒ Object
18 19 20 21 22 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 18 def value @value ||= @entry.value.to_s rescue "Binary data" end |
#value_size ⇒ Object
89 90 91 |
# File 'lib/solid_cache_dashboard/decorators/cache_entry_decorator.rb', line 89 def value_size @entry.value.to_s.bytesize end |