Coder Social home page Coder Social logo

object-cache's People

Contributors

dependabot-preview[bot] avatar jasperste avatar jeanmertz avatar jurriaan avatar koenrh avatar

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

Watchers

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

Forkers

iq-scm

object-cache's Issues

Still usable?

Hi I'd like to use this library but wondering if it's still in a usable state with Ruby 3 and actively maintained. Last commit is 2 years ago, thus my concern.

Replace 'Marshal' with JSON serialiser

The use of Marshal.load poses a security risk. It could lead to remote code execution when loading untrusted data. I don't think it is not beyond the realm of possibilities that for some reason some program or piece of code manages to update data stored at 'object-cache'-defined keys, which in turn is deserialised by 'object-cache' (and thus Marshal.load).

As far as I can tell this library only supports the serialisation and deserialisation of simple types, which means it is probably as easy as replacing Marshal with a JSON serialiser?

Add the option to return _stale_ values whilst refreshing in background

Currently this gem allows values to be cached until the expire, when this happens a new value is generated, cached and returned. This means that every ttl one user/client/connection needs to wait for the cache to refresh.

It would be great if you could specify the time after which a value is stale (time to stale?). Where stale means the value can still be used but a new version should be generated in the background.

Ex:

def get_highscore
  Cache.new(tts: 5.minutes, ttl: 10.minutes) {
    get_resource('https://example.org/api/highscore.json')
  }
end

# snip…snip…snip

puts get_highscore # first time, fetches data

sleep 1.minute
puts get_highscore # use cache

sleep 5.minutes
puts get_highscore # cache is stale, method returns immediately background job fetches new data
puts get_highscore # background job might still be busy, stale cache still used, no second job started

sleep 5.seconds
puts get_highscore # new data is used, timers reset

sleep 15.minutes
puts get_highscore # value completely expired, method blocks to fetch new data.

This way values are kept up-to-date and no user/client/connection has is blocked every once and a while.

Two more ideas:

  • Pluggable backend, defaulting to Thread.new. If this gem is used in an eventmachine environment eventmachine should be used.
  • Automatic stale. If you measure the average time a refresh takes, you can predict when a new version should be fetch. ex: tts = ttl - (measured_time*2) (this should be disabled by default).

Cheers,
—Koen

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.