Comments (5)
I've gone ahead and made a duplicate of your CachedModel and called ot MongoCachedModel,
Then inside that class I replaced the extend Model by extend Eloquent
And added use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
That's all that was needed to get it to work with mongodb models
Except that now I can't use the artisan flush command on that model because it's not an instance of "CachedModel"
Can you think of a more elegant way to handle this?
from laravel-model-caching.
I also ran into one problem so far when working with mongodb models. Unlike with mysql, sometimes the values are arrays themselves and that triggered a Array to String conversion error on these lines inside the CacheKey
$value = array_get($where, 'value');
$value .= $this->getTypeClause($where);
$value .= $this->getValuesClause($where);
I was able to fix it by changing it to
$value = array_get($where, 'value');
if (is_array($value)) {
$value = implode("_", $value);
}
$value .= $this->getTypeClause($where);
$value .= $this->getValuesClause($where);
from laravel-model-caching.
Interesting, I will see about adding this. If you can submit a PR that would expedite things, but it sounds like a good idea.
from laravel-model-caching.
Update: Doh.. I had totally forgot I had done another small change on my dev only.. inside the vendor files.. ugh.. and hadn't pushed it to my fork.. It was this change in the Cachable trait:
//if (is_a($this, CachedModel::class)) {
array_push($tags, str_slug(get_called_class()));
//}
hey @mikebronner I'm hoping maybe you can think of something here...
what I mentioned above is really the only small change I needed to do in order to get it to work with my mongodb models. This was working perfectly on my DEV environment. Mongo models were being invalidated exactly as you'd expect a mysql model to.. no biggie
but then tonight I deployed my changes to production.. and I'm baffled.
Mysql models are being invalidated, but not the mongo ones! And there are no errors being thrown at all.
I verified that I'm loading my fork correctly with that small change you see above. I cleared all caches.. opcache.. everything.. multiple times. I added \Log::debug in my _CachedMongoModel file which is a clone of CachedModel as I mentioned above. I added logging on the update/saved events and can confirm that it's going in there.. and it's executing the $instance->flushCache();.. and it's not throwing any errors but it won't flush the darn mongo models
I even connected through Medis.. a pretty cool Redis GUI client, and I compared the tag names on both my DEV and production.. and the tag names are the same. If I use the command line to flush models.. it works on DEV for both mysql and mongo tags.. but on Live it only works on mysql models
I made myself my own flush command btw because yours requires that the model be an instance of CachedModel so I just commented those out.
my .env file is almost the same on dev and live.. redis is used for all the drivers.. I really don't think this is an environment issue.. but maybe some obscure difference.. I just spent an hour trying to debug this before I had to revert
Anyway I am really out of ideas of why it isn't able to flush the mongo models on live.. the tags look identical.. ??
if you have any idea you'd really be helping me out here!
Thanks!
from laravel-model-caching.
Fixed in version 0.2.30. Please re-open if still a problem.
from laravel-model-caching.
Related Issues (20)
- What is cacheCooldownSecounds definition? HOT 1
- Add support for Laravel 10 HOT 2
- Object of class Illuminate\\Database\\Query\\Expression could not be converted to string HOT 6
- Since 0.12.4 I get error "GeneaLabs\LaravelModelCaching\CacheKey::processEnum(): Argument #1 ($value) must be of type BackedEnum|UnitEnum|string, null given, called in ...\vendor\genealabs\laravel-model-caching\src\CacheKey.php on line 409" HOT 25
- Cannot access "parent" when current class scope has no parent HOT 1
- Laravel v10.3.0 breaks LaravelModelCaching HOT 2
- checkCooldownAndFlushAfterPersisting(): Argument #2 ($relationship) must be of type string, array given, called in /var/www/html/vendor/genealabs/laravel-model-caching/src/Traits/ModelCaching.php on line 83 HOT 8
- Is table join supported? HOT 7
- The attribute [column3] either does not exist or was not retrieved for model HOT 1
- Stale cached value returned where(...)->first() HOT 4
- Fix for GeneaLabs\LaravelModelCaching\CacheKey::processEnum(): Argument #1 ($value) must be of type BackedEnum|UnitEnum|string, null given
- processEnum(): Argument #1 ($value) must be of type BackedEnum|UnitEnum|Illuminate\Database\Query\Expression|string, null given HOT 2
- Conflict with Spatie Schemaless
- Laravel 11 upgrade blocked by laravel-pivot-events dependency HOT 1
- Missing import in CachedBuilder?
- Fix failing tests HOT 1
- Uuid fromBytes throwing a error HOT 1
- Observer for Pivot Model not firing HOT 3
- Bug: CacheKey::getValuesFromBindings(): Return value must be of type string, null returned | when where value is null HOT 1
- Object of class Illuminate\Database\Query\Expression could not be converted to string
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-model-caching.