Akashic Records

sscache : SHOP.COM Cache System 본문

오래된글/Java

sscache : SHOP.COM Cache System

Andrew's Akashic Records 2018. 4. 9. 13:09
728x90

sscache : SHOP.COM Cache System


"SHOP.COM"이라는 영국 쇼핑몰 사이트에서 사용중인 Object Cache API을 Open Source로 제공하고 있습니다. 최신 버전은 0.3 버전은 2008년 12월 19일 쯤에 등록이 되었습니다. 간략한 테스트를 해보고 느낀 점을 정리 해봤습니다.

  1. 순수 Java 개발

  2. CacheServer을 실행하고 Client가 TCP/IP로 접속하는 방식

  3. CacheServer에서 Object 저장에 File DB을 사용하고 Data File과 Index File 2개가 생성 됨

  4. Serializable 을 상속 받은 Object 만 저장 가능. Serializable을 상속 받지 않는 Object을 저장 하려 할경우 Error을 발생하지 않고 File DB에도 저장되지 않는다. 이게 버그인지 사용을 잘못한것인지 출력 로그가 없어 확인 불가능

  5. CacheServer가 구동되지 않은 상태에서 Cache를 사용하려 해도 클라이언트에 오류가 출력되지 않는다. 마치 정상 동작하는 것 처럼 보이지만 실제 CacheServer에 Object는 저장되지 않음.

  6. Multi-CacheServer 사용 가능

  7. CacheServer을 Handling 할 수 있는 API가 너무 부족함.

"SHOP.COM" 사이트에서는 많은 서버에 Application과 ChachServer을 설치해 사용하고 있으며, 각 서버 사양은 Windows 64bit OS에 8GB 메모리라고 합니다.


DownLoad Site

http://code.google.com/p/sccache/


Sample Code

CacheServer

package com.naver.blog.inter999.sccache;

import java.io.File;

import java.io.IOException;

import com.shop.cache.api.server.SCServer;

import com.shop.cache.api.server.SCServerContext;

import com.shop.cache.api.server.SCServerFactory;

import com.shop.cache.api.storage.SCStorage;

import com.shop.cache.imp.common.ShopComCacheFactory;

import com.shop.cache.imp.storage.ccdb2.CCDB2Parameters;

import com.shop.cache.imp.storage.ccdb2.CCDB2StorageFactory;

public class CacheServer {

public static void main(String[] args) throws Exception {

try {

SCServerFactory factory = ShopComCacheFactory.getServerFactory();

SCServerContext context = factory.newContext();

context.port(1111); <- 서비스 Port

SCStorage db = CCDB2StorageFactory.create(new CCDB2Parameters());

db.open(new File("C:/DownLoad")); <- File DB 생성 위치

SCServer server = factory.newServer(context, db);

server.join();

} catch (IOException e) {

e.printStackTrace();

} catch (InterruptedException e) {

e.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

}

}

}


CacheClient

package com.naver.blog.inter999.sccache;

import java.net.InetSocketAddress;

import com.shop.cache.api.client.io.SCClientContext;

import com.shop.cache.api.client.io.SCClientFactory;

import com.shop.cache.api.client.io.SCClientManager;

import com.shop.cache.api.client.main.SCCache;

import com.shop.cache.api.client.main.SCDataBlock;

import com.shop.cache.imp.common.ShopComCacheFactory;

public class CacheClient {

public static void main(String[] args) throws Exception {

SCClientFactory clientFactory = ShopComCacheFactory.getClientFactory();

SCClientContext context = clientFactory.newContext();

context.address(new InetSocketAddress("192.168.13.76", 1111)); <- Server IP, Port

SCClientManager manager = clientFactory.newClientManager(context);

SCCache myCache = new SCCache(manager);

String myKey = System.currentTimeMillis()+"";

MyObject obj = new MyObject();

obj.setName("Hurukku");

obj.setAddress("SEOUL");

obj.setAge(16);

myCache.put(new SCDataBlock(myKey, obj));

String myKey2 = System.currentTimeMillis()+500+"";

obj = new MyObject();

obj.setName("Hurukku2");

obj.setAddress("SEOUL2");

obj.setAge(16);

myCache.put(new SCDataBlock(myKey2, obj));

System.out.println(myCache.getConnectionList());

System.out.println((MyObject)myCache.get(new SCDataBlock(myKey)));

System.out.println((MyObject)myCache.get(new SCDataBlock(myKey2)));

}

}


MyObject

package com.naver.blog.inter999.sccache;

import java.io.Serializable;

public class MyObject implements Serializable {

private static final long serialVersionUID = 20081223L;

private String name;

private int age;

private String address;

private String phone;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

public String getPhone() {

return phone;

}

public void setPhone(String phone) {

this.phone = phone;

}

public String toString() {

return "name : "+name+", address : "+address+", age : "+age;

}

}


Test

1. 설치한 sccachhe의 lib 폴더 밑에 있는 모든 Jar 파일을 Class Path에 추가합니다.

2. CacheServer 실행

- CacheServer가 실행되면 지정된 File DB 폴더에 33MB 정도의 .db 파일이 생성됩니다.

3. CacheClient 실행

[2 client(s), 1. 192.168.13.76 - listclients, 2. 192.168.13.76 - put]

name : Hurukku, address : SEOUL, age : 16

name : Hurukku2, address : SEOUL2, age : 16

- CacheClient가 실행되고 나면 File DB 폴더에 16MB 정도의 .idx Index 파일이 생성됩니다.



728x90
Comments