Implement locking for Laravel cache component

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Fixed
    • Priority: Major - P3
    • laravel-4.3.0
    • Affects Version/s: None
    • Component/s: Laravel
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      https://github.com/mongodb/laravel-mongodb/issues/2609

      • Laravel-mongodb Version: #.#.#
      • PHP Version: #.#.#
      • Database Driver & Version:

      Description:

      I have issue when store data to cache lock with MongoDB driver. error also occurs when dispatch a job implements ShouldBeUnique.

      Method acquire Illuminate\Cache\DatabaseLock catch QueryException to update record cache lock table. But with mongodb driver connection throw MongoDB\Driver\Exception\BulkWriteException so can not excute snippet code in catch block

      Illuminate\Cache\DatabaseLock

      public function acquire()
          {
              $acquired = false;        try {
                  $this->connection->table($this->table)->insert([
                      'key' => $this->name,
                      'owner' => $this->owner,
                      'expiration' => $this->expiresAt(),
                  ]);            $acquired = true;
              } catch (QueryException $e) {
                  $updated = $this->connection->table($this->table)
                      ->where('key', $this->name)
                      ->where(function ($query) {
                          return $query->where('owner', $this->owner)->orWhere('expiration', '<=', time());
                      })->update([
                          'owner' => $this->owner,
                          'expiration' => $this->expiresAt(),
                      ]);            $acquired = $updated >= 1;
              }        if (random_int(1, $this->lottery[1]) <= $this->lottery[0]) {
                  $this->connection->table($this->table)->where('expiration', '<=', time())->delete();
              }        return $acquired;
          } 

      Steps to reproduce

              Assignee:
              Jérôme Tamarelle
              Reporter:
              Tom Selander
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: