OK, thank you.
Unfortunately, what you want is dangerous, because the Album model is not
> statically cached and could change at any time.
>
It can be cached too.
You are also using the frozen: false option, which means the Artist
> objects are distinct objects every time, and would have fresh association
> caches. What are you trying to do is not something I want to add direct
> support for.
`frozen: false` is necessary for caching + editing. Cache, but when it
updates — make DB query and restart the application.
On Tuesday, February 27, 2018 at 9:43:42 PM UTC+3, Jeremy Evans wrote:
>
> On Tuesday, February 27, 2018 at 7:59:41 AM UTC-8, Alexander Popov wrote:
>>
>> Hello!
>>
>> We’re using static_cache plugin, and now we have model with this plugin
>> and with associations.
>>
>> But we found that this plugin re-creates instances of models, so
>> associations cache doesn’t work.
>>
>> Example:
>>
>> class Artist < Sequel::Model
>> plugin :static_cache, frozen: false
>>
>> one_to_many :albumsend
>> class Album < Sequel::Model
>> many_to_one :artistend
>> Artist.all.first.albums# SELECT * FROM "albums" WHERE ("albums"."artist_id"
>> = 1)Artist.all.first.albums# SELECT * FROM "albums" WHERE
>> ("albums"."artist_id" = 1)
>>
>> We’re planning use cached model with associations in each, and this fact
>> about non-caching associations is sad. :(
>>
>> Can you change something for associations caching?
>>
>> Ugly and dangerous work-around is:
>>
>> class Artist < Sequel::Model
>> # ...
>>
>> set_dataset dataset.eager(:albums)end
>> Artist.cache.each_value { |artist| ... }
>>
>> Thank you.
>>
> Unfortunately, what you want is dangerous, because the Album model is not
> statically cached and could change at any time. You are also using the
> frozen: false option, which means the Artist objects are distinct objects
> every time, and would have fresh association caches. What are you trying
> to do is not something I want to add direct support for.
>
> You are probably best off making a copy of the static_cache plugin and
> then modifying it to do what you want, or just overriding
> Artist.static_cache_object to call super and then set the appropriate value
> in the associations cache for the returned object. Watch out for
> cache-invalidation issues.
>
> 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.