Giter Club home page Giter Club logo

Comments (5)

vesper8 avatar vesper8 commented on July 29, 2024

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.

vesper8 avatar vesper8 commented on July 29, 2024

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.

mikebronner avatar mikebronner commented on July 29, 2024

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.

vesper8 avatar vesper8 commented on July 29, 2024

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.

mikebronner avatar mikebronner commented on July 29, 2024

Fixed in version 0.2.30. Please re-open if still a problem.

from laravel-model-caching.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.