| @@ 29-58 (lines=30) @@ | ||
| 26 | /** |
|
| 27 | * Class CacheEvictInterceptor |
|
| 28 | */ |
|
| 29 | class CacheEvictInterceptor extends AbstractCache |
|
| 30 | { |
|
| 31 | /** |
|
| 32 | * @param MethodInvocation $invocation |
|
| 33 | * |
|
| 34 | * @return mixed |
|
| 35 | */ |
|
| 36 | public function invoke(MethodInvocation $invocation) |
|
| 37 | { |
|
| 38 | $annotation = $invocation->getMethod()->getAnnotation($this->annotation) ?? new $this->annotation([]); |
|
| 39 | $keys = $this->generateCacheName($annotation->cacheName, $invocation); |
|
| 40 | if (!is_array($annotation->key)) { |
|
| 41 | $annotation->key = [$annotation->key]; |
|
| 42 | } |
|
| 43 | $keys = $this->detectCacheKeys($invocation, $annotation, $keys); |
|
| 44 | ||
| 45 | // detect use cache driver |
|
| 46 | $cache = $this->detectCacheRepository($annotation); |
|
| 47 | ||
| 48 | if ($annotation->allEntries) { |
|
| 49 | $cache->flush(); |
|
| 50 | ||
| 51 | return $invocation->proceed(); |
|
| 52 | } |
|
| 53 | $result = $invocation->proceed(); |
|
| 54 | $cache->forget($this->recursiveImplode($this->join, $keys)); |
|
| 55 | ||
| 56 | return $result; |
|
| 57 | } |
|
| 58 | } |
|
| 59 | ||
| @@ 29-53 (lines=25) @@ | ||
| 26 | /** |
|
| 27 | * Class AroundCachePutAspect |
|
| 28 | */ |
|
| 29 | class CachePutInterceptor extends AbstractCache |
|
| 30 | { |
|
| 31 | /** |
|
| 32 | * @param MethodInvocation|\Ray\Aop\ReflectiveMethodInvocation $invocation |
|
| 33 | * |
|
| 34 | * @return mixed |
|
| 35 | */ |
|
| 36 | public function invoke(MethodInvocation $invocation) |
|
| 37 | { |
|
| 38 | $annotation = $invocation->getMethod()->getAnnotation($this->annotation) ?? new $this->annotation([]); |
|
| 39 | $keys = $this->generateCacheName($annotation->cacheName, $invocation); |
|
| 40 | if (!is_array($annotation->key)) { |
|
| 41 | $annotation->key = [$annotation->key]; |
|
| 42 | } |
|
| 43 | $keys = $this->detectCacheKeys($invocation, $annotation, $keys); |
|
| 44 | // detect use cache driver |
|
| 45 | $cache = $this->detectCacheRepository($annotation); |
|
| 46 | $result = $invocation->proceed(); |
|
| 47 | if ($result !== null) { |
|
| 48 | $cache->put($this->recursiveImplode($this->join, $keys), $result, $annotation->lifetime); |
|
| 49 | } |
|
| 50 | ||
| 51 | return $result; |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||