Giter Site home page Giter Site logo

memery's People

Contributors

alexwayfer avatar earlopain avatar jelf avatar martinstreicher avatar nevinera avatar tycooon 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  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

memery's Issues

Would you mind cutting a release?

We have a change merged in the middle of last year, but it looks like the latest release is still from 2021 - would you mind dropping another version?

debug with memery

code:

require "memery"
require "pry"

class A
  include Memery

  memoize def test
  end
end

a = A.new

binding.pry

and in pry execute $ a.test

current behavior:

> $ a.test

From: .../.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/memery-1.3.0/lib/memery.rb:58:
Owner: #<Module:0x000055b9f6294130>
Visibility: public
Signature: test(*args, &block)
Number of lines: 17

define_method method_name do |*args, &block|
  if block || (condition && !instance_exec(&condition))
    return super(*args, &block)
  end

  store = (@_memery_memoized_values ||= {})[method_key] ||= {}

  if store.key?(args) &&
    (ttl.nil? || Memery.monotonic_clock <= store[args][:time] + ttl)
    return store[args][:result]
  end

  result = super(*args)
  @_memery_memoized_values[method_key][args] =
    { result: result, time: Memery.monotonic_clock }
  result
end

preferred behavior:

> $ a.test

From: test.rb:6:
Owner: A
Visibility: public
Signature: test()
Number of lines: 2

def test
end

Is it possible?

Is there a way to recalculate just one memoized attribute?

I know that the prevailing memoized_attribute(true) approach is somewhat flaky but is there a way to recalculate a given memoized property without expiring the entire cache so to speak?

As well I apologize if my knowledge of memery is somewhat limited but does it memoize functions that accept arguments?

Support (opt-in?) pattern that complies with recent ruby object shape performance optimization?

Reading this essay:

https://island94.org/2023/10/writing-object-shape-friendly-code-in-ruby

And the reddit conversation:

https://www.reddit.com/r/ruby/comments/16xwjh9/writing_object_shape_friendly_code_in_ruby/

Made me think there was a place for a gem that would support memoization that complies with recent ruby object shape performance optimizations.

It's a bit tricky, because it does require hooking into initializer too. I haven't looked at memery code atall to see how hard it would be (or if you are already compliant, in which case you could advertise that in README?), but at least theoretically should be possible?

In an ideal world, memery API would otherwise remain the same. Perhaps you'd opt into the new behavior with include Memery::Optimized instead of just include Memery or something like that.

Caching of methods with default arguments

It looks like default method arguments are not cached separately if they change implicitly, take this for example:

Object.include Memery

I18n = Struct.new(:locale).new(:en)

def test_method(locale: I18n.locale)
  locale
end

Object.memoize :test_method

test_method
# => :en, correct

test_method(locale: :fr)
# => :fr, correct

I18n.locale = :fr

test_method
# => :en, wrong, should be :fr

Didn't have a chance to look at the code yet, but wanted to raise the issue before I forget :-)

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.