First-level cache in Agile Data?


#1

Hi, I am finding my ways around “Agila Data”.
Can you help me understand how it deals with a problem of multiple DB requests?

For example, we have a command handler and authorizer classes, first executes a command, second authorizes a user to do so. Both are decoupled and both can query the same kind of information from a DB.

Is there a mechanism in Agile Data which will cache responses or somehow reduces the number of similar/equal requests?

Thanks


#2

Hi Dima.

I’m not fully understanding the command/authorize pattern, but to answer your question on reducing queries:

  1. Agile Data tries best not to perform multiple queries in the first place. Here are some usage patterns: https://medium.com/@romaninsh/many-to-many-relations-with-agile-data-410d5d8f0442

  2. When you wish to cache things elsewhere, then you can load models from a different persistence. A good example is here: https://github.com/atk4/login/blob/master/src/Login.php#L55

Technically, Model you can attempt to load Model from any persistence:

$persistence->tryLoad($user, $cache_key);

I haven’t coded persistence implementation for Memcache or Redis, but that’s something I was meaning to do for some time.