added redis cache for IR binaries
This commit is contained in:
42
src/main/java/net/irext/decoder/model/IRBinary.java
Normal file
42
src/main/java/net/irext/decoder/model/IRBinary.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package net.irext.decoder.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filename: IRBinary.java
|
||||||
|
* Revised: Date: 2018-12-30
|
||||||
|
* Revision: Revision: 1.0
|
||||||
|
* <p>
|
||||||
|
* Description: Remote binary in cache
|
||||||
|
* <p>
|
||||||
|
* Revision log:
|
||||||
|
* 2018-12-30: created by strawmanbobi
|
||||||
|
*/
|
||||||
|
public class IRBinary {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
private byte[] binary;
|
||||||
|
|
||||||
|
public IRBinary(Integer id, byte[] binary) {
|
||||||
|
this.id = id;
|
||||||
|
this.binary = binary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IRBinary() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getBinary() {
|
||||||
|
return binary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBinary(byte[] binary) {
|
||||||
|
this.binary = binary;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import net.irext.decoder.model.DecodeSession;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filename: RedisRepository.java
|
* Filename: IDecodeSessionRepository.java
|
||||||
* Revised: Date: 2018-12-29
|
* Revised: Date: 2018-12-29
|
||||||
* Revision: Revision: 1.0
|
* Revision: Revision: 1.0
|
||||||
* <p>
|
* <p>
|
||||||
@@ -14,7 +14,7 @@ import java.util.Map;
|
|||||||
* Revision log:
|
* Revision log:
|
||||||
* 2018-12-29: created by strawmanbobi
|
* 2018-12-29: created by strawmanbobi
|
||||||
*/
|
*/
|
||||||
public interface RedisRepository {
|
public interface IDecodeSessionRepository {
|
||||||
|
|
||||||
Map<Object, Object> findAllDecodeSessions();
|
Map<Object, Object> findAllDecodeSessions();
|
||||||
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package net.irext.decoder.redisrepo;
|
||||||
|
|
||||||
|
import net.irext.decoder.model.IRBinary;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filename: IRRepository.java
|
||||||
|
* Revised: Date: 2018-12-30
|
||||||
|
* Revision: Revision: 1.0
|
||||||
|
* <p>
|
||||||
|
* Description: IR binary cache for performance optimization on decoding
|
||||||
|
* <p>
|
||||||
|
* Revision log:
|
||||||
|
* 2018-12-30: created by strawmanbobi
|
||||||
|
*/
|
||||||
|
public interface IIRBinaryRepository {
|
||||||
|
|
||||||
|
Map<Object, Object> findAllIRBinaries();
|
||||||
|
|
||||||
|
void add(IRBinary irBinary);
|
||||||
|
|
||||||
|
void delete(Integer id);
|
||||||
|
|
||||||
|
IRBinary find(Integer id);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.irext.decoder.redisrepo;
|
package net.irext.decoder.redisrepo.impl;
|
||||||
|
|
||||||
import net.irext.decoder.model.DecodeSession;
|
import net.irext.decoder.model.DecodeSession;
|
||||||
|
import net.irext.decoder.redisrepo.IDecodeSessionRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.HashOperations;
|
import org.springframework.data.redis.core.HashOperations;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
@@ -10,7 +11,7 @@ import javax.annotation.PostConstruct;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filename: RedisRepositoryImpl.java
|
* Filename: IDecodeSessionRepositoryImpl.java
|
||||||
* Revised: Date: 2018-12-29
|
* Revised: Date: 2018-12-29
|
||||||
* Revision: Revision: 1.0
|
* Revision: Revision: 1.0
|
||||||
* <p>
|
* <p>
|
||||||
@@ -20,19 +21,19 @@ import java.util.Map;
|
|||||||
* 2018-12-29: created by strawmanbobi
|
* 2018-12-29: created by strawmanbobi
|
||||||
*/
|
*/
|
||||||
@Repository
|
@Repository
|
||||||
public class RedisRepositoryImpl implements RedisRepository {
|
public class DecodeSessionRepositoryImpl implements IDecodeSessionRepository {
|
||||||
private static final String KEY = "SESSION_KEY";
|
private static final String KEY = "SESSION_KEY";
|
||||||
|
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
private HashOperations hashOperations;
|
private HashOperations hashOperations;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public RedisRepositoryImpl(RedisTemplate<String, Object> redisTemplate){
|
public DecodeSessionRepositoryImpl(RedisTemplate<String, Object> redisTemplate) {
|
||||||
this.redisTemplate = redisTemplate;
|
this.redisTemplate = redisTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void init(){
|
private void init() {
|
||||||
hashOperations = redisTemplate.opsForHash();
|
hashOperations = redisTemplate.opsForHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,13 +45,11 @@ public class RedisRepositoryImpl implements RedisRepository {
|
|||||||
hashOperations.delete(KEY, id);
|
hashOperations.delete(KEY, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DecodeSession find(final Integer id){
|
public DecodeSession find(final Integer id) {
|
||||||
return (DecodeSession) hashOperations.get(KEY, id);
|
return (DecodeSession) hashOperations.get(KEY, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Object, Object> findAllDecodeSessions(){
|
public Map<Object, Object> findAllDecodeSessions() {
|
||||||
return hashOperations.entries(KEY);
|
return hashOperations.entries(KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package net.irext.decoder.redisrepo.impl;
|
||||||
|
|
||||||
|
import net.irext.decoder.model.IRBinary;
|
||||||
|
import net.irext.decoder.redisrepo.IIRBinaryRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.HashOperations;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filename: IIRBinaryRepositoryImpl.java
|
||||||
|
* Revised: Date: 2018-12-29
|
||||||
|
* Revision: Revision: 1.0
|
||||||
|
* <p>
|
||||||
|
* Description: Redis cache class
|
||||||
|
* <p>
|
||||||
|
* Revision log:
|
||||||
|
* 2018-12-29: created by strawmanbobi
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public class IRBinaryRepositoryImpl implements IIRBinaryRepository {
|
||||||
|
private static final String KEY = "SESSION_KEY";
|
||||||
|
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
private HashOperations hashOperations;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public IRBinaryRepositoryImpl(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
this.redisTemplate = redisTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void init() {
|
||||||
|
hashOperations = redisTemplate.opsForHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(final IRBinary IRBinary) {
|
||||||
|
hashOperations.put(KEY, IRBinary.getId(), IRBinary.getBinary());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(final Integer id) {
|
||||||
|
hashOperations.delete(KEY, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IRBinary find(final Integer id) {
|
||||||
|
return (IRBinary) hashOperations.get(KEY, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Object, Object> findAllIRBinaries() {
|
||||||
|
return hashOperations.entries(KEY);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user