集群Spring应用程序的Hazelcast缓存

时间:2016-07-06 14:49:02

标签: caching hazelcast

我们最近将Spring应用程序与一个数据库支持的2个节点进行了集群。 我们的应用程序具有动态菜单(每个用户都有不同的菜单选项),因为每次用户登录时我们都没有足够的缓存,我们点击数据库并根据用户安全性过滤菜单选项。我们希望每次用户通过引入Cache登录时都避免访问数据库。

我正在阅读关于hazelcast缓存http://hazelcast.org/use-cases/caching/的内容,我注意到有多个可用于缓存的选项,例如In-Memory Data Grid/NoSqlJcacheSpring Cache但不确定哪一个是最佳解决方案缓存Menu项(String类型)。根据我的理解,我觉得Spring Cache是我的用例的正确解决方案,如果没有,请建议我其他的hazelcast缓存选项。

1 个答案:

答案 0 :(得分:5)

Spring Caching支持Hazelcast(或Hazelcast提供与Spring Caching class A{ private int x = 13; public A(){ //use default value for x } public A(int x){ this.x = x; } } class B extends A { private int y = 0; public B(){ //use default value for x and y } public B(int x){ super(x); //use default value for y } public B(int x, int y){ super(x); this.y = y; } } 的集成)。 如果您使用 Spring 4 和更高版本,则可以使用Spring Framework的JCache caching支持。 您可以找到使用示例here。 寻找override func viewDidLayoutSubviews() { var newOrientation: AVCaptureVideoOrientation var orientation: UIDeviceOrientation = UIDevice.currentDevice().orientation switch (orientation) { case .Portrait: newOrientation = .Portrait; var frame = buttonsview.frame frame.size.width = 320 frame.size.height = 50 let totalWidth : CGFloat = self.view.bounds.size.width var x:CGFloat = 0.0; if( totalWidth>320) { x = (totalWidth-320.0)/2.0 } frame.origin.x = x frame.origin.y = self.view.bounds.size.height-50 buttonsview.frame = frame buttonsview.layoutSubviews() view.addSubview(buttonsview) self.activityView.center = self.view.center break; case .PortraitUpsideDown: newOrientation = .PortraitUpsideDown; var frame = buttonsview.frame frame.size.width = 320 frame.size.height = 50 let totalWidth : CGFloat = self.view.bounds.size.width var x:CGFloat = 0.0; if( totalWidth>320) { x = (totalWidth-320.0)/2.0 } frame.origin.x = x frame.origin.y = self.view.bounds.size.height-50 buttonsview.frame = frame buttonsview.layoutSubviews() view.addSubview(buttonsview) self.activityView.center = self.view.center break case .LandscapeLeft: newOrientation = .LandscapeRight; var frame = buttonsview.frame frame.size.width = 320 frame.size.height = 50 let totalWidth : CGFloat = self.view.bounds.size.width var x:CGFloat = 0.0; if( totalWidth>320) { x = (totalWidth-320.0)/2.0 } frame.origin.x = x frame.origin.y = self.view.bounds.size.height-50 buttonsview.frame = frame view.addSubview(buttonsview) self.activityView.center = self.view.center break case .LandscapeRight: newOrientation = .LandscapeLeft; var frame = buttonsview.frame frame.size.width = 320 frame.size.height = 50 let totalWidth : CGFloat = self.view.bounds.size.width var x:CGFloat = 0.0; if( totalWidth>320) { x = (totalWidth-320.0)/2.0 } frame.origin.x = x frame.origin.y = self.view.bounds.size.height-50 buttonsview.frame = frame view.addSubview(buttonsview) self.activityView.center = self.view.center break; default: newOrientation = .Portrait; var frame = buttonsview.frame frame.size.width = 320 frame.size.height = 50 let totalWidth : CGFloat = self.view.bounds.size.width var x:CGFloat = 0.0; if( totalWidth>320) { x = (totalWidth-320.0)/2.0 } frame.origin.x = x frame.origin.y = self.view.bounds.size.height-50 buttonsview.frame = frame buttonsview.layoutSubviews() view.addSubview(buttonsview) self.activityView.center = self.view.center } let newSize = self.view.bounds.size; previewLayer.position = CGPointMake(0.5 * newSize.width, 0.5 * newSize.height); } override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) { CATransaction.begin() CATransaction.setAnimationDuration(duration) CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)); updatePreviewLayerForOrientation(toInterfaceOrientation); CATransaction.commit(); } func updatePreviewLayerForOrientation(interfaceOrientation: UIInterfaceOrientation) { // Correct position of previewLayer let newSize = view.bounds.size; previewLayer.position = CGPointMake(0.5 * newSize.width, 0.5 * newSize.height); var angle: Double! // Rotate the previewLayer, in order to have camera picture right switch interfaceOrientation { case .Portrait: angle = 0 case .LandscapeLeft: angle = M_PI/2 case .LandscapeRight: angle = -M_PI/2 default: // .PortraitUpsideDown angle = M_PI } previewLayer.setAffineTransform(CGAffineTransformMakeRotation(CGFloat(angle))) } 个项目。

也支持Spring Boot。观看在线讲座recording,阅读我的blog post,找到代码示例here

如果您有任何问题,请与我们联系。

谢谢