sitepoint-editors / Rauth

A basic annotation-based ACL package for PHP
MIT License
41 stars 4 forks source link

Cache Hydration #2

Open Swader opened 8 years ago

Swader commented 8 years ago

There should be an option to fill the cache / Rauth instance with pre-parsed or pre-configured values, so that it doesn't have to parse things on every call.

Several configuration formats could supported, but I don't care much for YAML and similar. I'd much rather have:

  1. A tool that traverses an entire src folder and feeds the built array to the cache / Rauth instance
  2. A way to pass a built array to the cache / Rauth instance

For the purpose of separation of concerns, it would probably be better not to feed through Rauth, but I feel weird about feeding Cache directly, too. Something else entirely?

AndrewCarterUK commented 8 years ago

With the PHP array cache you could throw in a constructor that gives it an initial array to start with.

Then you could have this array dumped to a PHP file (var_export). This way you'd also leverage the benefits of the opcache and not need to do any additional parsing.

Swader commented 8 years ago

Hmm, good idea, that. It would change the interface signature for the cache constructor, though, no? Would this be an okay change? Or would this skip the interface and apply only to the array cache?

AndrewCarterUK commented 8 years ago

Constructors (how the object is made) shouldn't feature on an interface (how the object behaves).

Do you plan on adding other cache options? I'd say make this an option in the configuration of 'ArrayCache' in the same way that server details would be an option for 'RedisCache'.

Wanting to actively warm up the cache is a requirement you probably only want with an array cache anyway - as you lose everything once the PHP instance dies (unlike with an external cache that could stay alive).

AndrewCarterUK commented 8 years ago

You could even change it to file cache and make the constructor accept a file path.

On construction you would then load the PHP array in the file and you could hook the destruct method to save any changes.

Swader commented 8 years ago

Constructors (how the object is made) shouldn't feature on an interface (how the object behaves).

Quite right :+1:

Do you plan on adding other cache options?

Yeah, eventually, but focusing on the interface and the array one for now, that's enough for current needs.

Wanting to actively warm up the cache is a requirement you probably only want with an array cache anyway

Is it, though? I'd want to feed things into a Redis or whatever other cache, too, especially in heavy apps like Symfony.

On construction you would then load the PHP array in the file and you could hook the destruct method to save any changes.

Sounds good. Think you could whip up a PR with that?

AndrewCarterUK commented 8 years ago

Wanting to actively warm up the cache is a requirement you probably only want with an array cache anyway

Is it, though? I'd want to feed things into a Redis or whatever other cache, too, especially in heavy apps like Symfony.

Sounds like we have two different issues here.

  1. Making a FileCache that is persistent between PHP instances.
  2. Creating a cache warm up routine.

I can sort you out a PR for the FileCache over the weekend (out tonight and Saturday).

Swader commented 8 years ago

Cool, I'll see if I don't do it first, thanks