How to pass parameters to cache function?

I’m trying to implement a cache system but I’m having problem to pass paramenters fo the cache callable function.

Example:




$slug = "test";

$model = MyModel::getDb()->cache(function ($db) {

            return MyModel::find()->with(['something'])->where(['slug' => $slug])->one();

        });



How can I pass the $slug variable to inside the function called on cache()?


function ($db) use ($slug) {

http://php.net/manual/en/functions.anonymous.php

Great!! Thank you very much