Code Monkey home page Code Monkey logo

Comments (7)

KimpShreyan avatar KimpShreyan commented on June 1, 2024

What if you use
protected $touches = ['Product'];

on Country Model can you confirm
I want to use the in one of my project

from laravel-model-caching.

mikebronner avatar mikebronner commented on June 1, 2024

@geniqtech the key question is how you are making changes to the table. If you make the changes via Eloquent queries, the cache should be invalidated. If you make changes to the table data directly, the cache has no way of knowing you made updates.

from laravel-model-caching.

geniqtech avatar geniqtech commented on June 1, 2024

@mikebronner We are making changes via Eloquent queries. Referring to the example in my use case above, if we make changes to countries table via Eloquent queries, the cached item is not invalidated.

from laravel-model-caching.

geniqtech avatar geniqtech commented on June 1, 2024

@KimpShreyan AFAIK "$touches" only updates the "updated_at" column and is meant for a different purpose.

from laravel-model-caching.

mikebronner avatar mikebronner commented on June 1, 2024

@geniqtech Could you provide the query you are using to make changes?

from laravel-model-caching.

geniqtech avatar geniqtech commented on June 1, 2024

Here's the code snippet:

        // Check before update
        $data = Country::select('countries.*', 'products.name AS product_name')
            ->leftJoin('products', 'products.country_code', 'countries.country_code')->get();
        Log::info($data);

        // Update Product
        $product = Product::find(1);
        $product->name = 'banana';
        $product->save();

        // Check again after update
        $data = Country::select('countries.*', 'products.name AS product_name')
            ->leftJoin('products', 'products.country_code', 'countries.country_code')->get();
        Log::info($data);

Logs Output
local.INFO: [{"country_code":"US","name":"United States","product_name":"apple"},{"country_code":"JP","name":"Japan 1","product_name":"orange"}]
local.INFO: [{"country_code":"US","name":"United States","product_name":"apple"},{"country_code":"JP","name":"Japan 1","product_name":"orange"}]

from laravel-model-caching.

thauanvargas avatar thauanvargas commented on June 1, 2024

Hello guys!
Any updates in this?
I'm also having some issues with join, seems to not be invalidating cache correctly, is it supported ?

This is how I'm populating the database:

        PostComment::create([
            'comment' => $message,
            'post_id' => $taskId,
            'created_by' => $user->id
        ]);

How i'm querying:

        $postComments = Post::select(
            'user.id',
            'user.uuid',
            'user.name',
            'post_comments.created_at',
            'post_comments.comment'
        )->join(
            'post_comments',
            'post_comments.task_id',
            'posts.id'
        )->join(
            'users',
            'user.id',
            'post_comments.created_by'
        )->where('posts.uuid', $uuid)->orderBy('post_comments.created_at', 'desc');

This query doesn't show any updated results.

But, if I change to this:

  $postComments = PostComments::select(
          'user.id',
          'user.uuid',
          'user.name',
          'post_comments.created_at',
          'post_comments.comment'
      )->join(
          'posts',
          'posts.id',
          'post_comments.task_id'
      )->join(
          'user',
          'user.id',
          'post_comments.created_by'
    )->where('posts.uuid', $uuid)->orderBy('post_comments.created_at', 'desc');

it works, but before I updating my laravel-model-caching the first query was working properly if I'm not wrong.

@mikebronner @geniqtech

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.