On Thursday, September 13, 2018 at 10:50:48 AM UTC-7, Alexander Popov wrote:
>
> > "there is no way"?  There is always a way. :)
>
> Sorry, I mean there is now _elegant_ way, which I know. :) Ruby-way, 
> Ruby-native way, something like that.
>
> > def Locale.call(h)
>
> I don't like `instance_variable_set` much, but yeah, it's an option. 
>
> > or use the after_initialize plugin
>
> OK, this looks better. But… doesn't work with `static_cache` plugin and 
> `Model.first` method.
>
> > If that still doesn't get you what you want, I'm probably not 
> understanding the problem correctly, so please put together a minimal 
> self-contained reproducible example showing the problem in that case.
>
> I have (static cached) locales in DB and in R18n library (from YAML 
> files). I want to bind them.
>
> So… instead of something like:
>
> ```ruby
> def r18n
>   return @r18n if defined? @r18n
>   @r18n = R18n.locales.find { |locale| locale.code == code }
> end
> ```
>
> I want to make this `find` in initialization (or in `code` setter), once, 
> also because `Locale` has `static_cache` plugin.
>

You want to make sure you set up the appropriate code before loading the 
static_cache plugin, as after you load it, it may be too late.  However, 
starting with Sequel 5.12, you can call load_cache after loading the plugin 
to repopulate the cache, so you could load the plugin, make your changes, 
then call load_cache afterward.

The standard way to have caching work for frozen objects is to cache before 
freezing, so you may want to try that as well (again before loading the 
static cache plugin or calling load_cache):

  def freeze
    r18n
    super
  end

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to