'캐시'에 해당되는 글 2건

  1. 2015.11.09 :: SpringMVC+Memcached(4)
  2. 2015.11.09 :: SpringMVC + memcached maven 및 bean 설정 (2)
개발관련/memcached 2015. 11. 9. 11:12

3번과 dto는 동일하다. 

하지만 bean은 변경이 된다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<aop:aspectj-autoproxy />
<!-- 이부분은 아마도 버그인듯 문서에는 없었는데 안쓰면 에러가 난다. -->
    <import resource="simplesm-context.xml" />
    <bean name="defaultMemcachedClient" class="com.google.code.ssm.CacheFactory">
        <property name="cacheClientFactory">
            <bean name="cacheClientFactory"
                class="com.google.code.ssm.providers.xmemcached.MemcacheClientFactoryImpl" />
        </property>
        <property name="addressProvider">
            <bean class="com.google.code.ssm.config.DefaultAddressProvider">
                <property name="address" value="192.168.0.105:11211" />
            </bean>
        </property>
        <property name="configuration">
            <bean class="com.google.code.ssm.providers.CacheConfiguration">
                <property name="consistentHashing" value="true" />
            </bean>
        </property>
    </bean>
    <bean class="com.google.code.ssm.Settings">
        <property name="order" value="500" />
    </bean>
 
cs

service는 다음과 같이 설정하면 된다. 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Override
    @CacheEvict(value="cachable")
    public boolean delete( long idx) {
        userDao.delete(idx);
        return false;
    }
@Override
    @CachePut(value="cachable", key="#userDTO.idx")
    public UserDTO write( UserDTO userDTO) {
        return userDao.save(userDTO);
    }
 
    @Override
    @Cacheable(value="cachable", key="#idx")
    public UserDTO read( long idx) {
        UserDTO userDTO =  userDao.findOne(idx);
//        userDao.save(userDTO);
        return userDTO;
    }
cs

기존 ehcached와 동일하다. number 계열도 된다. 

아마도 난 이 방법으로 사용할 듯 보인다. 


소스 주소는 https://github.com/zest133/Memcached.git 여기로.. 

posted by 제스트
:
개발관련/memcached 2015. 11. 9. 10:29

사용 환경은 다음과 같다. 

springMVC 3.2, hsqldb, jpa, hibernate, xmemcached-provider, spymemcached-provider ,com.google.code.simple-spring-memcached 이렇게 메이븐에 defendancy를 추가한다. 

먼저 @UpdateSingleCache 이런 식으로 사용하는 방법을 먼저 설명한다. maven 설정 자체는 두 가지 방식다 동일하다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
         <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>3.2.0</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.8.Final</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.simple-spring-memcached</groupId>
            <artifactId>xmemcached-provider</artifactId>
            <version>3.6.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.simple-spring-memcached</groupId>
            <artifactId>spymemcached-provider</artifactId>
            <version>3.6.0</version>
        </dependency>
 
        <dependency>
            <groupId> com.google.code.simple-spring-memcached </groupId>
            <artifactId>spring-cache</artifactId>
            <version>3.6.0</version>
        </dependency>
cs

bean 등록은 다음과 같이 한다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!-- spring data jpa 설정 -->
 
    <!-- jpa repository가 위치한 패키지 경로 등록 -->
    <jpa:repositories base-package="com.zest.memcached.user.dao"
        entity-manager-factory-ref="entityManagerFactory" />
 
    <!-- 하이버네이트의 SessionFactory 에 상응하는 jpa의 EntityManagerFactory 등록 -->
    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
        <property name="dataSource" ref="dataSource" />
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop<!-- Hsql 형식에 맞게 변환해주는 클래스 -->
                <prop key="hibernate.connection.pool_size">1</prop>
                <prop key="hibernate.connection.shutdown">true</prop<!-- hsql에 있는 마지막 연결이 끊어지면 데이터베이스 shutdown 하는 플래그 -->
                <prop key="hibernate.show_sql">true</prop<!-- SQL 출력 -->
                <prop key="hibernate.hbm2ddl.auto">create</prop<!-- 테이블 자동 생성 -->
            </props>
        </property>
        <!-- 엔티티 정의된 클래스들이 있는 패키지 등록 -->
        <property name="packagesToScan" value="com.zest.memcached.user.dto" />
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"></property>
    </bean>
    <!-- spring data jpa 설정 끝 -->
                
 
 
cs

위 설명은 jpa 설정 부분이다. 

xmemcached 설정은 다음과 같다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<aop:aspectj-autoproxy />
<!-- aop 관련 설정 -->
    <import resource="simplesm-context.xml" />
    <bean name="defaultMemcachedClient" class="com.google.code.ssm.CacheFactory">
        <property name="cacheClientFactory">
            <bean name="cacheClientFactory"
                class="com.google.code.ssm.providers.xmemcached.MemcacheClientFactoryImpl" />
        </property>
        <property name="addressProvider">
            <bean class="com.google.code.ssm.config.DefaultAddressProvider">
                <property name="address" value="192.168.0.105:11211" />
            </bean>
        </property>
        <property name="configuration">
            <bean class="com.google.code.ssm.providers.CacheConfiguration">
                <property name="consistentHashing" value="true" />
            </bean>
        </property>
    </bean>
    <bean class="com.google.code.ssm.Settings">
        <property name="order" value="500" />
    </bean>
                
 
 
cs

코드 부분은 다음에............ 


posted by 제스트
: