Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache Database Driver not Following Database "Sticky" Setting #22763

Closed
benyanke opened this issue Jan 12, 2018 · 6 comments
Closed

Cache Database Driver not Following Database "Sticky" Setting #22763

benyanke opened this issue Jan 12, 2018 · 6 comments

Comments

@benyanke
Copy link

benyanke commented Jan 12, 2018

  • Laravel Version: 5.4
  • PHP Version: 7.1.x
  • Database Driver & Version: MySQL

Description:

It appears the database driver for the cache is not obeying the database sticky setting (which points all reads on a given request to the write host if the session had any writes).

Using Elastic Beanstalk and an RDS backend, using the read replicas (which typically have a delay of about 20 ms), I have a section of code which ensures the cache is working on deploy. The following code fails for me whenever I'm using a read replica.

      // Cache set above
    
      // Test delete
      Cache::forget($key);

      // Check to see if key was deleted successfully.
      if(!Cache::has($key)) {
        $deleteSuccess = true;
      } else {
        $deleteSuccess = false;   // This branch taken - not what is expected
      }

This test code does not show the key as deleted. However, if I add a sleep longer than the replication delay, it works as expected - which is why I assume this is a sticky issue.

Note that this issue does not show itself with a single DB server.

      // Cache set above
    
      // Test delete
      Cache::forget($key);
      sleep(1);
      // Check to see if key was deleted successfully.
      if(!Cache::has($key)) {
        $deleteSuccess = true; // This branch taken - works as expected.
      } else {
        $deleteSuccess = false;      
      }
@laurencei
Copy link
Contributor

You are running Laravel 5.4.

I did the PR for sticky writes to Laravel 5.5.

Try upgrading, then let me know if you have any issues.

@benyanke
Copy link
Author

I don't have time to upgrade my whole app, but I may look at using your patch in the meantime. Do you have the PR number handy?

@themsaid themsaid reopened this Jan 14, 2018
@laurencei
Copy link
Contributor

Here it is: #20445

@benyanke
Copy link
Author

I am newer to laravel, but is there any chance it would get backported to the 5.4.x version, or is the sole answer to upgrade to 5.5? I can do some testing to get a PR for 5.4 if that is "a thing."

@laurencei
Copy link
Contributor

It's up to Taylor - but I would suggest the odds are very low (almost zero).

5.4 is EOL. 5.5 is current and also the LTS version.

The time you spend backporting the feature and testing it - you could just upgrade to 5.5. It's a quick upgrade.

@benyanke
Copy link
Author

Ok. I will look into upgrading when I have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants