Skip to content

Commit

Permalink
Merge pull request mewebstudio#221 from bernhardh/master
Browse files Browse the repository at this point in the history
Fix too long cache key issue for memcached
  • Loading branch information
mewebstudio authored Apr 22, 2021
2 parents 41a3dac + 88fbe94 commit c9181e1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public function create(string $config = 'default', bool $api = false)
}

if ($api) {
Cache::put('captcha_record_' . $generator['key'], $generator['value'], $this->expire);
Cache::put($this->get_cache_key($generator['key']), $generator['value'], $this->expire);
}

return $api ? [
Expand Down Expand Up @@ -483,6 +483,16 @@ public function check(string $value): bool

return $check;
}

/**
* Returns the md5 short version of the key for cache
*
* @param string $key
* @return string
*/
protected function get_cache_key($key) {
return 'captcha_' . md5($key);
}

/**
* Captcha check
Expand All @@ -494,7 +504,7 @@ public function check(string $value): bool
*/
public function check_api($value, $key, $config = 'default'): bool
{
if (!Cache::pull('captcha_record_' . $key)) {
if (!Cache::pull($this->get_cache_key($key))) {
return false;
}

Expand Down

0 comments on commit c9181e1

Please sign in to comment.