用Java实现Memcache [英] Implementing Memcache in Java

查看:114
本文介绍了用Java实现Memcache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


因此,最后我的Java智能卡实用程序

Hi
So finally my Java smart card Utility

(See my previous questions) 

是通过完全成熟的方式开发的.但是现在,新作品在

is developed n working in fully fledged way. But Now the new work is on

Memcache

I have to implement memcache service in java for MS SQL server 2008 for Databases of high latency n redundancy n low availability.

Any thoughts on how to start the activity are most welcome. Please provide some hint n ideas about memcache service to be implemented in java.



非常感谢你们在我的第一次活动中的支持.

谢谢&问候,
Anil Kumar



Thanks a lot Guys for your support in my first activity .

Thanks & Regards,
Anil Kumar

推荐答案

您是否拥有门面 [<在您的应用程序中使用a href ="http://en.wikipedia.org/wiki/F" target ="_ blank" title ="New Window"> ^ ]?

如果是这样,那么很简单,您只需扩展写/读和删除机制.

如何在现有应用程序中实现外观:
-设置一个类"FacadeService".在您的GUI启动之前触发了该事件.
-FacadeService implements Serializable.该类需要一个方法"getInstance()",该方法可以返回FacadeService的一个实例.
这是您的一般入口点. FacadeService拉起外观的其余部分(在此示例中为将客户存储在其中的外观):

Do you have a facade[^] in your aplication?

if so it''s simple, you would only have to extend the write/read and delete mechanisms.

How to implement a facade into an existing application:
- set up a class "FacadeService". that one is triggered BEFORE your GUI starts.
- FacadeService implements Serializable. the class needs a methode "getInstance()" which gives back a instance of FacadeService.
This is your general entrance point. FacadeService pulls up the rest of the facade (in this example a facade to store Customers in):

import java.io.Serializable;

public class FacadeService implements Serializable {
	private static final long serialVersionUID = 1L;

	private static final FacadeService oFacadeService = new FacadeService();
	
	private final CustomerFacade oCustomerFacade = new CustomerFacade();
	
	public FacadeService(){
		// maybe do something or just leave unfunctional
	}
	
	public static FacadeService getInstance(){
		return oFacadeService;
		
	}
	
	public CustomerFacade getCustomerFacade(){
		return oCustomerFacade;
	}
}





import java.io.Serializable;

public class CustomerFacade implements Serializable {
	private static final long serialVersionUID = 1L;

	private final CustomerFacade oCustomerFacade = new CustomerFacade();
	
	public CustomerFacade(){
		this.ignition();
	}
	
	private void ignition() {
		// load data at startup from DB
	}

	public CustomerFacade getInstance(){
		return oCustomerFacade;
	}
}



-现在您的完整GUI应该从此外观读取:



- now your complete GUI should read from this facade:

private CustomerFacade getCustomerFacade(){
  return FacadeService.getInstance().getCustomerFacade();
}



-确保可以在运行时存储所有内容.创建复制数据库中每个对象的对象.
-确保在启动时正在读取数据库以填充外观.
-确保每次值更改时都在写入数据库.您可以设置可以帮助您的一般方法.甚至一个类"DatabaseConnector"也将有助于收集所有的读/写/修改方法.确保将数据库操作设为异步(线程化 [



- Make sure you can store everything at runtime. Create objects that dublicate each object in the database.
- make sure you are reading the DB at startup to fill your facade.
- make sure you are writing to the DB each time a value changes. You can set up for that general methods that help you. Even a class "DatabaseConnector" would be helpful to gather all the read/write/modify methods. make sure the DB actions are made asynchronous (Threading[^]) so they do not block your application.
- make sure your GUI is not reading from the DB aside of the facade. Your application should be able to run without the DB/just from the Facade data (the facade is empty if the database could not be read).

NOTE:
I know that this is not the intended use of Serializable and the design is not general applicable. But it''s a simple, easy to implement approach to add a facade to an existing application.


这篇关于用Java实现Memcache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆