AWS MySQL是否缓存数据? Laravel 5

I'm making a simple API endpoint that returns an access code for an event.

If the event does not have access code, then it gets assigned one and saved in the database. Then, it checks if it's currently public or private. If private, return access code, if public, return empty string.

This is the endpoint controller:

public function getAc($eventId) {
    // Pull event
    $event = $this->eventService->api->getEventForce($eventId);

    // If no access code for the event, generate one and update event record accordingly
    if ($event->access_code == null) {

        $access_code = $this->generateAccessCode();
        DB::update('update events set access_code = ? where id = ?', [$access_code, $eventId]);

        // Load updated event from DB.
        $event = $this->eventService->api->getEventForce($eventId);
    }

    // Is the event currently private? return access code
    if ($event->privacy=='private') {
        return $event->access_code; // HERE: value comes back from the API but on MySQL Workbench it's still null.
    }

    // Is it public ? return empty string.
    else {
        return '';
    }
}

My problem is that even though everything works as expected. When access_code is created it does come back from the api.

However when I check the record on MySQL Workbench (that connects to AWS Instance) it's still null! event though I pulled it from the database as a non-null value using the API endpoint.

Little confused with your code. From debugging I'd suggest checking your API for this issue. From what I can see you're doing this:

  1. Ask API for event with ID 1
  2. Check if event has a parameter
  3. If no parameter, update using local DB

So I'm left asking, if the problem is with the API, why are you updating using the local instance of the DB? Furthermore could this be resolved using events? (I'm going to call your class something other than event so not to get confusing)

For instance:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Party extends Model {
    public $table = 'parties';
    public $fillable = [];

    public static function boot() {
        parent::boot();

        static::creating(function($party) {
            //create some fancy access code
            $access_code = 'heyyyy';
            //Check not manually set 
            if (!isset($party->attributes['access_code']) || is_null($party->attributes['access_code'])) {
                $party->access_code = $access_code;
            }
        }
    }
}

Now every time you create an event or 'party' using Party::create(); or $party = new Party; $party->save(); the creating event will pick up the save and also assign the access_code if you haven't set it manually like $party->access_code = 'you can\'t come';.

That's my thought anyway. However in your immediate case I think you need to ask yourself some more questions like:

  1. Does the DB object from the instance of Laravel I'm using have access to the database to save said object?
  2. Do I need to call the API in order to update my entity/model?
  3. If the instance of Laravel I'm using from the \DB::update call have the same credentials as my API?
  4. If this is a command or job, do my code changes affect it? Do I need to restart a supervisor/cron command to re-instance my code?
  5. Who wrote this API? Is it reliable enough to use? And does it have documentation?