[Catalyst] Caching an expensive "global" calculation?

tirveni yadav yadav.tirveni at gmail.com
Fri Apr 14 15:01:31 GMT 2017


On Wed, Apr 12, 2017 at 4:14 PM, Dr. Jennifer Nussbaum
<bg271828 at yahoo.com> wrote:
>
> Hi,
>
> This may not be strictly Catalyst-related, but I'd be grateful for any help - I dont know much about
> either caching or making things available throughout an app :-(
>
> I have an app that uses a number of different outside configuration files; which one it uses depends on
> several factors, and it will be the same one per request cycle. Parsing each file is an expensive
> calculation. Originally I read it at the beginning of the cycle and passed the resulting variable around,
> but my models are now so complicated that this has gotten tedious, and I wanted to do something
> like have a utility method MyApp::Utilities->get_outside_config($id) that any model can call when it
> needs to. However, I dont want to have to recalculate it in every get_outside_config call.
>
> Whats the best way of handling this? The config is used very often, and could be regarded as global,
> but also most of my models are non-Catalyst ones that are glued in, so $c isnt available to them. The
> config files dont change often.
>

Caching is a good choice for this problem.

Store result of your calculations as a hash in a fastmmap/redis.
Do also store the timestamp in the hash.

Use the hash for all your subsequent request.
And, all of these requests check timestamp for staleness before
deciding to use the hash or go for calculations again.

Redis Hash operations.

-- 
Regards,

Tirveni Yadav
www.udyansh.org

What is this Universe ? From what it arises ? Into what does it go?
In freedom it arises, In freedom it rests and into freedom it melts away.
Upanishads.



More information about the Catalyst mailing list