class FlyAdmin::PageCache
Constants
- EXPIRATION_TIMEOUT
Attributes
rails_cache[RW]
Public Class Methods
new()
click to toggle source
# File lib/fly_admin/page_cache.rb, line 8 def initialize @rails_cache = ActiveSupport::Cache::MemoryStore.new end
Public Instance Methods
clear()
click to toggle source
# File lib/fly_admin/page_cache.rb, line 53 def clear @rails_cache.clear end
clear_element(elem)
click to toggle source
After saving footer, clear cache and check if from imbs source(now - from db)
# File lib/fly_admin/page_cache.rb, line 38 def clear_element(elem) @rails_cache.delete_matched(elem) new_text = check_footer(elem) write_with_date(elem, new_text) end
http_load(name, paysite, country)
click to toggle source
# File lib/fly_admin/page_cache.rb, line 89 def http_load(name, paysite, country) name = (name == 'content') ? 'footer' : name service = SiteConfig['service_code'] link = "/#{name}/#{service}.#{paysite}.#{country}.html" uri = URI("http://www.bornpay.com#{link}") res = Net::HTTP.get_response(uri) message = "#{res.code} , message: #{res.message}, url: http://bornpay.com#{link}" API_LOG.info "GET FlyAdmin::Footer : #{message} " if res.code == '200' && res.message == 'OK' res.body.force_encoding("UTF-8") else "" end end
read(elem)
click to toggle source
Get footers like this footer_wap_ru Get pages (unsubscribe etc) like this page_mt_en
# File lib/fly_admin/page_cache.rb, line 15 def read(elem) text = @rails_cache.read(elem) expired_in = @rails_cache.read("#{elem}_expired_an") unless text text = check_footer(elem) # Write to Rails cache like # elem = content_wap_ru write_with_date(elem, text) else if Time.now > expired_in new_text = check_footer(elem) unless new_text.empty? @rails_cache.clear write_with_date(elem, new_text) return new_text end end end text end
write(name, text)
click to toggle source
# File lib/fly_admin/page_cache.rb, line 49 def write(name, text) @rails_cache.write(name, text) end
write_with_date(elem, text)
click to toggle source
# File lib/fly_admin/page_cache.rb, line 44 def write_with_date(elem, text) write(elem, text) write("#{elem}_expired_an", Time.now + EXPIRATION_TIMEOUT) end