Skip to content

Commit 700ec43

Browse files
committed
Import the code from initial fork https://github.com/mihaicostin/hibernate-memcached
1 parent 03077c5 commit 700ec43

File tree

55 files changed

+4148
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4148
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Idea IDE files
2+
.idea
3+
*.ipr
4+
*.iws
5+
*.iml
6+
7+
#output files
8+
target
9+
10+
release.properties
11+
pom.xml.releaseBackup
12+
nb-configuration.xml

pom.xml

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.github.mihaicostin</groupId>
6+
<artifactId>hibernate-l2-memcached</artifactId>
7+
<version>1.0.0</version>
8+
<name>hibernate-l2-memcached</name>
9+
<description>A library for using Memcached as a second level distributed cache in Hibernate.</description>
10+
<url>https://github.com/mihaicostin/hibernate-l2-memcached</url>
11+
<packaging>jar</packaging>
12+
13+
<licenses>
14+
<license>
15+
<name>Apache License, Version 2.0</name>
16+
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
17+
</license>
18+
</licenses>
19+
20+
<developers>
21+
<developer>
22+
<name>Mihai Costin</name>
23+
<url>http://mihaicostin.github.io/</url>
24+
<timezone>+3</timezone>
25+
</developer>
26+
</developers>
27+
28+
<scm>
29+
<connection>scm:git:git@github.com:mihaicostin/hibernate-l2-memcached.git</connection>
30+
<developerConnection>scm:git:git@github.com:mihaicostin/hibernate-l2-memcached.git</developerConnection>
31+
<url>https://github.com/mihaicostin/hibernate-l2-memcached</url>
32+
</scm>
33+
34+
<distributionManagement>
35+
<snapshotRepository>
36+
<id>ossrh</id>
37+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
38+
</snapshotRepository>
39+
</distributionManagement>
40+
41+
<properties>
42+
<hibernate-core.version>4.3.11.Final</hibernate-core.version>
43+
<spymemcached.version>2.11.6</spymemcached.version>
44+
<slf4j-api.version>1.5.6</slf4j-api.version>
45+
46+
<junit.version>4.4</junit.version>
47+
<gmaven.version>1.5</gmaven.version>
48+
<groovy.version>1.6.3</groovy.version>
49+
<hsqldb.version>2.3.2</hsqldb.version>
50+
<slf4j-log4j12.version>1.5.6</slf4j-log4j12.version>
51+
</properties>
52+
53+
<build>
54+
<plugins>
55+
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-compiler-plugin</artifactId>
59+
<version>3.2</version>
60+
<configuration>
61+
<source>1.7</source>
62+
<target>1.7</target>
63+
<encoding>UTF-8</encoding>
64+
</configuration>
65+
</plugin>
66+
<plugin>
67+
<artifactId>maven-assembly-plugin</artifactId>
68+
<configuration>
69+
<descriptorRefs>
70+
<descriptorRef>bin</descriptorRef>
71+
<descriptorRef>src</descriptorRef>
72+
</descriptorRefs>
73+
</configuration>
74+
</plugin>
75+
<plugin>
76+
<groupId>org.codehaus.mojo</groupId>
77+
<artifactId>groovy-maven-plugin</artifactId>
78+
<version>1.5</version>
79+
<executions>
80+
<execution>
81+
<goals>
82+
<goal>generateTestStubs</goal>
83+
<goal>testCompile</goal>
84+
</goals>
85+
</execution>
86+
</executions>
87+
</plugin>
88+
89+
<!-- Allow writing tests in Groovy -->
90+
<plugin>
91+
<groupId>org.codehaus.gmaven</groupId>
92+
<artifactId>gmaven-plugin</artifactId>
93+
<version>${gmaven.version}</version>
94+
<executions>
95+
<execution>
96+
<goals>
97+
<goal>generateTestStubs</goal>
98+
<goal>testCompile</goal>
99+
</goals>
100+
</execution>
101+
</executions>
102+
<configuration>
103+
<providerSelection>1.7</providerSelection>
104+
<source>src/main/groovy</source>
105+
</configuration>
106+
<dependencies>
107+
<dependency>
108+
<groupId>org.codehaus.gmaven.runtime</groupId>
109+
<artifactId>gmaven-runtime-2.0</artifactId>
110+
<version>${gmaven.version}</version>
111+
<exclusions>
112+
<exclusion>
113+
<groupId>org.codehaus.groovy</groupId>
114+
<artifactId>groovy-all</artifactId>
115+
</exclusion>
116+
</exclusions>
117+
</dependency>
118+
<dependency>
119+
<groupId>org.codehaus.groovy</groupId>
120+
<artifactId>groovy-all</artifactId>
121+
<version>${groovy.version}</version>
122+
</dependency>
123+
</dependencies>
124+
</plugin>
125+
126+
<!-- Releasing to OSSRH -->
127+
<plugin>
128+
<groupId>org.sonatype.plugins</groupId>
129+
<artifactId>nexus-staging-maven-plugin</artifactId>
130+
<version>1.6.5</version>
131+
<extensions>true</extensions>
132+
<configuration>
133+
<serverId>ossrh</serverId>
134+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
135+
<autoReleaseAfterClose>false</autoReleaseAfterClose>
136+
</configuration>
137+
</plugin>
138+
139+
</plugins>
140+
</build>
141+
142+
<dependencies>
143+
144+
<dependency>
145+
<groupId>org.hibernate</groupId>
146+
<artifactId>hibernate-core</artifactId>
147+
<version>${hibernate-core.version}</version>
148+
<scope>provided</scope>
149+
</dependency>
150+
<dependency>
151+
<groupId>net.spy</groupId>
152+
<artifactId>spymemcached</artifactId>
153+
<version>${spymemcached.version}</version>
154+
</dependency>
155+
<dependency>
156+
<groupId>org.slf4j</groupId>
157+
<artifactId>slf4j-api</artifactId>
158+
<version>${slf4j-api.version}</version>
159+
</dependency>
160+
161+
162+
<!-- Test dependencies-->
163+
<dependency>
164+
<groupId>org.slf4j</groupId>
165+
<artifactId>slf4j-log4j12</artifactId>
166+
<version>${slf4j-log4j12.version}</version>
167+
<scope>test</scope>
168+
</dependency>
169+
<dependency>
170+
<groupId>junit</groupId>
171+
<artifactId>junit</artifactId>
172+
<version>${junit.version}</version>
173+
<scope>test</scope>
174+
</dependency>
175+
<dependency>
176+
<groupId>org.hsqldb</groupId>
177+
<artifactId>hsqldb</artifactId>
178+
<version>${hsqldb.version}</version>
179+
<scope>test</scope>
180+
</dependency>
181+
<dependency>
182+
<groupId>org.codehaus.groovy</groupId>
183+
<artifactId>groovy-all</artifactId>
184+
<version>${groovy.version}</version>
185+
<scope>test</scope>
186+
</dependency>
187+
188+
</dependencies>
189+
190+
191+
<profiles>
192+
<profile>
193+
<id>release</id>
194+
195+
<activation>
196+
<activeByDefault>false</activeByDefault>
197+
<property>
198+
<name>release</name>
199+
</property>
200+
</activation>
201+
202+
<build>
203+
<plugins>
204+
<plugin>
205+
<groupId>org.apache.maven.plugins</groupId>
206+
<artifactId>maven-source-plugin</artifactId>
207+
<version>2.4</version>
208+
<executions>
209+
<execution>
210+
<id>attach-sources</id>
211+
<goals>
212+
<goal>jar-no-fork</goal>
213+
</goals>
214+
</execution>
215+
</executions>
216+
</plugin>
217+
<plugin>
218+
<groupId>org.apache.maven.plugins</groupId>
219+
<artifactId>maven-javadoc-plugin</artifactId>
220+
<version>2.10.1</version>
221+
<configuration>
222+
<encoding>UTF-8</encoding>
223+
<failOnError>false</failOnError>
224+
</configuration>
225+
<executions>
226+
<execution>
227+
<id>attach-javadocs</id>
228+
<goals>
229+
<goal>jar</goal>
230+
</goals>
231+
</execution>
232+
</executions>
233+
</plugin>
234+
<plugin>
235+
<groupId>org.apache.maven.plugins</groupId>
236+
<artifactId>maven-gpg-plugin</artifactId>
237+
<version>1.6</version>
238+
<executions>
239+
<execution>
240+
<id>sign-artifacts</id>
241+
<phase>verify</phase>
242+
<goals>
243+
<goal>sign</goal>
244+
</goals>
245+
</execution>
246+
</executions>
247+
</plugin>
248+
</plugins>
249+
</build>
250+
251+
</profile>
252+
</profiles>
253+
254+
255+
</project>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* Copyright 2015, the original author or authors.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package com.mc.hibernate.memcached;
17+
18+
import com.mc.hibernate.memcached.keystrategy.Sha1KeyStrategy;
19+
20+
public class Config {
21+
22+
public static final String PROP_PREFIX = "hibernate.memcached.";
23+
24+
private static final String CACHE_TIME_SECONDS = "cacheTimeSeconds";
25+
public static final String PROP_CACHE_TIME_SECONDS = PROP_PREFIX + CACHE_TIME_SECONDS;
26+
27+
private static final String CLEAR_SUPPORTED = "clearSupported";
28+
public static final String PROP_CLEAR_SUPPORTED = PROP_PREFIX + CLEAR_SUPPORTED;
29+
30+
private static final String MEMCACHE_CLIENT_FACTORY = "memcacheClientFactory";
31+
public static final String PROP_MEMCACHE_CLIENT_FACTORY = PROP_PREFIX + MEMCACHE_CLIENT_FACTORY;
32+
33+
private static final String DOGPILE_PREVENTION = "dogpilePrevention";
34+
public static final String PROP_DOGPILE_PREVENTION = PROP_PREFIX + DOGPILE_PREVENTION;
35+
36+
private static final String DOGPILE_PREVENTION_EXPIRATION_FACTOR = "dogpilePrevention.expirationFactor";
37+
public static final String PROP_DOGPILE_PREVENTION_EXPIRATION_FACTOR = PROP_PREFIX + DOGPILE_PREVENTION_EXPIRATION_FACTOR;
38+
39+
private static final String KEY_STRATEGY = "keyStrategy";
40+
41+
public static final int DEFAULT_CACHE_TIME_SECONDS = 300;
42+
public static final boolean DEFAULT_CLEAR_SUPPORTED = false;
43+
public static final boolean DEFAULT_DOGPILE_PREVENTION = false;
44+
public static final String DEFAULT_MEMCACHE_CLIENT_FACTORY = "com.mc.hibernate.memcached.spymemcached.SpyMemcacheClientFactory";
45+
46+
private PropertiesHelper props;
47+
private static final int DEFAULT_DOGPILE_EXPIRATION_FACTOR = 2;
48+
49+
public Config(PropertiesHelper props) {
50+
this.props = props;
51+
}
52+
53+
public int getCacheTimeSeconds(String cacheRegion) {
54+
int globalCacheTimeSeconds = props.getInt(PROP_CACHE_TIME_SECONDS,
55+
DEFAULT_CACHE_TIME_SECONDS);
56+
return props.getInt(cacheRegionPrefix(cacheRegion) + CACHE_TIME_SECONDS,
57+
globalCacheTimeSeconds);
58+
}
59+
60+
public String getKeyStrategyName(String cacheRegion) {
61+
String globalKeyStrategy = props.get(PROP_PREFIX + KEY_STRATEGY,
62+
Sha1KeyStrategy.class.getName());
63+
return props.get(cacheRegionPrefix(cacheRegion) + KEY_STRATEGY, globalKeyStrategy);
64+
}
65+
66+
public boolean isClearSupported(String cacheRegion) {
67+
boolean globalClearSupported = props.getBoolean(PROP_CLEAR_SUPPORTED,
68+
DEFAULT_CLEAR_SUPPORTED);
69+
return props.getBoolean(cacheRegionPrefix(cacheRegion) + CLEAR_SUPPORTED,
70+
globalClearSupported);
71+
}
72+
73+
public boolean isDogpilePreventionEnabled(String cacheRegion) {
74+
boolean globalDogpilePrevention = props.getBoolean(PROP_DOGPILE_PREVENTION,
75+
DEFAULT_DOGPILE_PREVENTION);
76+
return props.getBoolean(cacheRegionPrefix(cacheRegion) + DOGPILE_PREVENTION,
77+
globalDogpilePrevention);
78+
}
79+
80+
public double getDogpilePreventionExpirationFactor(String cacheRegion) {
81+
double globalFactor = props.getDouble(PROP_DOGPILE_PREVENTION_EXPIRATION_FACTOR,
82+
DEFAULT_DOGPILE_EXPIRATION_FACTOR);
83+
return props.getDouble(cacheRegionPrefix(cacheRegion) + DOGPILE_PREVENTION_EXPIRATION_FACTOR,
84+
globalFactor);
85+
}
86+
87+
public String getMemcachedClientFactoryName() {
88+
return props.get(PROP_MEMCACHE_CLIENT_FACTORY,
89+
DEFAULT_MEMCACHE_CLIENT_FACTORY);
90+
}
91+
92+
private String cacheRegionPrefix(String cacheRegion) {
93+
return PROP_PREFIX + cacheRegion + ".";
94+
}
95+
96+
public PropertiesHelper getPropertiesHelper() {
97+
return props;
98+
}
99+
}

0 commit comments

Comments
 (0)