Skip to content

Commit

Permalink
first draft "@Cache*" annotations should only be applied on concrete …
Browse files Browse the repository at this point in the history
…classes
  • Loading branch information
erwan-serandour committed Jan 24, 2025
1 parent 8483052 commit 6690481
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions rules/S7180/java/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
FIXME: add a description
== Why is this an issue?

// If you want to factorize the description uncomment the following line and create the file.
//include::../description.adoc[]
Annotating interfaces or interface methods with `@Cache*` annotations is not recommended. When using CGLIB-based proxies, these annotations will be ignored, and no caching proxy will be created.

== Why is this an issue?
=== What is the potential impact?

FIXME: remove the unused optional headers (that are commented out)
* *Confusing Code*: Developers may mistakenly believe that caching is in effect, leading to confusion and incorrect assumptions about application performance.

//=== What is the potential impact?
This rule raises an issue when an interface or an interface method is annotated with a `@Cache*` annotation.

== How to fix it
//== How to fix it in FRAMEWORK NAME

Move `@Cache*` annotation from interface or interface method to the concrete class.

=== Code examples

==== Noncompliant code example

[source,java,diff-id=1,diff-type=noncompliant]
----
FIXME
public interface ExampleService {
@Cacheable("exampleCache") //non compliant, interface method is annotated with @Cacheable
String getData(String id);
}
----

==== Compliant solution

[source,java,diff-id=1,diff-type=compliant]
----
FIXME
@Service
public class ExampleServiceImpl implements ExampleService {
@Cacheable("exampleCache")
@Override
public String getData(String id) {
// Implementation here
}
}
----

//=== How does this work?

//=== Pitfalls

//=== Going the extra mile


//== Resources
//=== Documentation
//=== Articles & blog posts
//=== Conference presentations
//=== Standards
//=== External coding guidelines
//=== Benchmarks
== Resources
=== Documentation
* Spring - https://docs.spring.io/spring-framework/reference/integration/cache/annotations.html#cache-annotation-enable[Declarative Annotation-based Caching]

0 comments on commit 6690481

Please sign in to comment.