我想要做的是拥有一个看起来很像 Spring 提供的 @Cacheable Annotation 的 Annotation。
在方法之上使用,它看起来如下所示:
@CleverCache(key = "'orders_'.concat(#id)")
public Order getOrder(int id) {
Run Code Online (Sandbox Code Playgroud)
当我使用 Cacheable 使用它时,它以某种方式能够解释这个 SpEL-Expression 并生成一个具有值的键orders_1234(对于 id=1234)
我的匹配建议如下所示:
@Around("CleverCachePointcut(cleverCache)")
public Object clevercache(ProceedingJoinPoint joinPoint, CleverCache cleverCache) throws Throwable {
String expression = cleverCache.key();
//FIXME: Please add working code here :D - extracting the key by interpreting the passed SpEL Expression in expression
Run Code Online (Sandbox Code Playgroud)
我绝对在那里得到了表达式,但我还没有弄清楚如何让它正确解释 SpEL-Expression。
另一个支持语法应该是key = "T(com.example.Utils).createCacheKey(#paramOfMethodByName)"用于创建密钥的静态助手被调用的地方。
知道这如何工作吗?我有片段的代码可在:https : //github.com/eiselems/spring-redis-two-layer-cache/blob/master/src/main/java/com/marcusisesele/example/twolayercache/ smartcache/ExampleAspect.java#L35
任何帮助真的很感激!
我正在尝试实现典型的gof复合模式:
在以后查询它时,我有点迷茫.例如,在没有任何祖先的情况下查询所有复合材料会有一个很好的方法吗?
我最初的想法是使用ActiveRecord创建类似的东西
class Component < ActiveRecord::Base
belongs_to :childrenable, :polymorphic => true
has_and_belongs_to_many: composites
end
class Leaf < ActiveRecord::Base
has_many: components, :as => :childrenable
end
class Composite < ActiveRecord::Base
has_many: components, :as => :childrenable
has_and_belongs_to_many :components
end
Run Code Online (Sandbox Code Playgroud)
那会有用吗?我将如何构建这样的列表(在稍后的视图中f.ex.):
CompositeA
->Item
->CompositeB
->ItemA
->CompositeC
->ItemA
->ItemB
Run Code Online (Sandbox Code Playgroud)
在查询时我只是有点迷失.这个问题有什么最佳做法吗?
polymorphism design-patterns ruby-on-rails composite rails-activerecord