Giter VIP home page Giter VIP logo

api_cache's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

api_cache's Issues

Explanation of period

Hi there,

I'm feeling pretty stupid, but could somebody (ideally you Martyn) explain the purpose of the :period attribute in the APICache options?

In particular if the value is smaller than :cache (i.e. the time-to-live), as it is in the example given in the documentation. Isn't it the case then that if the API is hit more frequently than :period, the cache should simply be current?

Or is the use case of :period that you want to avoid to call the API too frequently in case you manually invalidate the cache? Another idea: is this done to avoid concurrency issues, where many processes/threads simultaneously try to refetch a new value from the API in case the cached value's time-to-live is over?

:period is confusing and limiting - here are some suggestions

First of all wanna thank you for this utility gem! Just wanna share some constructive suggestions.

I believe period: 0 should be the default. A very common case is to get a result (here we wanna enforce a period), and to have an "update" get for the result (where it's very important to have NO period as updates could happen at any time) As a result in my code I cannot use :period at all, cause the :period set when I "get" is gonna block me from making updates (which might happen soon after)

Hope that makes sense. In short I suggest:

  • make period: 0 the default
  • Add an option to ignore the period, perhaps ignore_period: true (this would allow one to "update" at anytime while still having a period for actual fetches)

EDIT: Actually I realized that I didn't have to wrap my update request at all - just needed to delete the local cache after the update, so the "option to ignore period" prob isn't as useful as I thought... still think period should default to 0 to reduce confusion tho

Clarification

Hi
Is this cache method compatible with the HttParty gem.
I am using it to access flight information from a service. The response takes lots of time. Actually a lot of data is returned.

  1. Can it be used in tandem with Httparty. Or will I have to replace Httparty with this gem?
  2. Since it pertains to flight travel, info should be accurate. So any way to set the cache to expire with the expire data of the response.

Pls advise
Thanks.

Support conditional GET requests

I don't see any mention of conditional GET requests. If it's not supported, I'd certainly like it added. If it is supported, perhaps the readme could be updated?

Specifically, what I'm looking for is:

If I make an API request outside of the period, hit the API with appropriate If-Modified-Since and If-None-Match headers, and if the response is a 304 - Not Modified, then serve the cached response.

Notification mechanism if API call consistently failing

Currently, as long as stale data is available, the only notice you'll get that an API is failing is a warning in the logs. However, if for example, if the API you're consuming has changed, you'd like to be notified during the stale period so that you can update your code.

I'm thinking webhooks. Maybe a global configurable address which if supplied it would be pinged on failure during the stale period.

Get cached value without calling block?

So I have multiple values that I want to fetch in bulk but cache separately, is that possible with this gem? I think I could achieve this by fetching each key individually and then storing them individually, but this seems to be circumventing the library. Is there a better way to accomplish this?

memcached ServerIsMarkedDead

I'm building a gem and added memcached as a dependency but then when I add it:

require "coinmarketcap/wrapper/version"
 require "coinmarketcap/wrapper/api_client"
 require "coinmarketcap/wrapper/coin"
 require "coinmarketcap/wrapper/market_data"
 require 'json'
 require 'api_cache'
 require "moneta"
 require "memcached"

 module Coinmarketcap
   module Wrapper
     BASE_API_URL = "https://api.coinmarketcap.com/v1"

     APICache.store = Moneta.new(:Memcached)
   end
 end 

and then run bin/console I get an error:

Memcached::ServerIsMarkedDead: Key {"9aaf5eb3d6edd10f12643e3087b84d21"=>"127.0.0.1:11211:8"}

is there a configuration I am missing?

Upgrade to new Moneta Gem

Hi Martyrn,

Can I upgrade api_cache to use the latest version of the Moneta gem. This gem has a different but more importantly uniform interface for creating the stores. The use of this version will only require changes to the Markdown and specs.

Error: queried too recently

For some reason, when I try to fetch something, the error "queried too recently" is raised.

Cannot fetch url: queried too recently
.../api_cache-0.2.3/lib/api_cache/api.rb:81:in `check_queryable!'
.../api_cache-0.2.3/lib/api_cache/api.rb:35:in `get'
.../api_cache-0.2.3/lib/api_cache.rb:108:in `get'
lib/ext/nokogiri.rb:18:in `get_cached'
lib/ext/nokogiri.rb:32:in `get_cached'

I debugged and the cache_state is "missing". It makes sense because it is a fresh run.

My code that used APICache:

class Nokogiri::HTML::Document
  # Use open-uri to get document and set url accordingly.
  def self.get(url)
    raw = open(url)
    parse(raw, raw.base_uri.try(:to_s)) # handles redirected url
  end
end
module Nokogiri::HTML
  def self.get(url)
    Document.get(url)
  end
end

# with APICache
class Nokogiri::HTML::Document
  # Use open-uri to get document and set url accordingly.
  def self.get_cached(url)
    doc = APICache.get('nokogiri' << url) do
      get(url)
    end
    # If redirected, add new url to the cache as well
    if doc.url != url
      APICache.get('nokogiri' << doc.url) do
        doc
      end
    end
    doc
  end
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.