On Wed, Apr 12, 2017 at 4:14 PM, Dr. Jennifer Nussbaum
<bg271...@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.


Tirveni Yadav

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.

List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to