Skip to content

Instantly share code, notes, and snippets.

@shaiguitar
Created June 7, 2017 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaiguitar/49a1de6702db68e5c6bda7a099cbdb13 to your computer and use it in GitHub Desktop.
Save shaiguitar/49a1de6702db68e5c6bda7a099cbdb13 to your computer and use it in GitHub Desktop.
Fog-core cache expire policy example.
  1. Record cache set/fetch time.
Fog::Cache.write_metadata({:last_refreshed => Time.now})
  1. Create some custom expirey method
      EXPIRE_TIME = (60 * 60 * 24) # day old cache.
      
      def renew?
        last_refreshed = Fog::Cache.metadata[:last_refreshed]

        if last_refreshed.nil?
          # no metadata, cache is old
          return true
        end

        if (Time.now - last_refreshed) > EXPIRE_TIME
          return true
        else
          return false
        end
      end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment