On Wednesday, 30 April 2014 02:58:34 UTC+10, Jeremy Evans wrote:
>
> On Monday, April 28, 2014 8:34:46 PM UTC-7, russ m wrote:
>>
>>
>> My use case is a database that is caching resources from a crappy REST 
>> source that only supports "get resource by ID" and "get all resources 
>> modified since this timestamp" operations. At the moment the cache is 
>> updated on a schedule (so is always a little stale, and is read-only to our 
>> application), and I'd like to try out refreshing the cache on every 
>> retrieval of a Sequel::Model object.
>>
>
> If you are refreshing the cache on every retrieval, then you probably 
> should not be caching at all.
>
>>
Not a full refresh, but a "get resources modified since" the most recent 
last-modified time on each table - in practice this will usually return no 
or very few (ie <10) changed records.

Also, the local cache isn't there for speed but to be able to make useful 
queries against the published data, since the provided API is so thin.

 

> As far as I can tell I can't use the Sequel::Model#initialize like the 
> AfterInitialize 
>> plugin does, since model objects aren't instantiated unless the dataset 
>> query returns rows.
>>
>> Before I wade into datasets to see where/how to hook them, can anybody 
>> point me at a good spot to look at doing this?
>>
>
> The only place I can think of to do this is to override Dataset#each for 
> the model's dataset:
>
>   ModelClass.dataset_module{def each; refresh_cache; super end}
>

Thanks, I'll check that out.

 

> But that may refresh the cache more often than you want.  A better 
> approach if this is a web application is to add a before hook or rack 
> middleware that will reload the cache before the appropriate actions.  That 
> way you are only refreshing once per web request.
>
 
Throttling cache refreshes is the obvious first optimisation, but I was 
going to leave that until after I had a working implementation.


cheers

R.

-- 
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 http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to