Skip to content

Commit

Permalink
Rename methods to be like Collection ones to increase its discoverabi…
Browse files Browse the repository at this point in the history
…lity
  • Loading branch information
rocboronat committed Jul 4, 2016
1 parent 1547eac commit e1f0ff0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cache.remove("key"); // and remove it if you want.
cache.get("unExistingKey"); // If something doesn't exists, it returns null
cache.get("tooOldKey"); // The same if a key is too old

cache.removeAll(); // You can also clean it,
cache.clean(); // You can also clean it,
cache.size(); // and ask it how many elements it has

QNCache<String> stringCache = new QNCacheBuilder().createQNCache(); //You can also make it typesafe
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/fewlaps/quitnowcache/QNCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void startAutoReleaseServiceIfNeeded() {
ses.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
removeTooOldValues();
purge();
}
}, autoReleaseInSeconds, autoReleaseInSeconds, TimeUnit.SECONDS);
}
Expand Down Expand Up @@ -125,14 +125,14 @@ public void remove(String key) {
/**
* Removes all the elements of the cache, ignoring if they're dead or alive
*/
public void removeAll() {
public void clear() {
cache.clear();
}

/**
* Removes the dead elements of the cache, to free memory
*/
void removeTooOldValues() {
void purge() {
Iterator<Map.Entry<String, QNCacheBean<T>>> it = cache.entrySet().iterator();

while (it.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class IntroducingQNCacheTest {

@SuppressWarnings("UnusedAssignment")
Expand All @@ -25,7 +22,7 @@ public void theCodeOfTheReadmeWorks() {
cache.get("unExistingKey"); // If something doesn't exists, it returns null
cache.get("tooOldKey"); // The same if a key is too old

cache.removeAll(); // You can also clean it,
cache.clear(); // You can also clean it,
cache.size(); // and ask it how many elements it has

QNCache<String> stringCache = new QNCacheBuilder().createQNCache(); //You can also make it typesafe
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/fewlaps/quitnowcache/MemoryReleaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ public void manualReleaseMemoryWorks() throws InterruptedException {
cache.set("3", A_VALUE, 3000);

//checking that forgettingOldValues work
cache.removeTooOldValues();
cache.purge();
assertEquals(3, cache.sizeCountingDeadAndAliveElements());

Thread.sleep(1000);
cache.removeTooOldValues();
cache.purge();
assertEquals(2, cache.sizeCountingDeadAndAliveElements());

Thread.sleep(1000);
cache.removeTooOldValues();
cache.purge();
assertEquals(1, cache.sizeCountingDeadAndAliveElements());

Thread.sleep(1000);
cache.removeTooOldValues();
cache.purge();
assertEquals(0, cache.sizeCountingDeadAndAliveElements());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void removingAllValuesWorks() {
cache.set(A_KEY, A_VALUE, TWO_HOURS);
cache.set(ANOTHER_KEY, ANOTHER_VALUE, THREE_DAYS);

cache.removeAll();
cache.clear();

assertNull(cache.get(A_KEY));
assertNull(cache.get(ANOTHER_KEY));
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/fewlaps/quitnowcache/SizeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void sizeWorksAfterRemovingAllTheElements() {
cache.set(A_KEY, A_VALUE, ONE_SECOND);
cache.set(ANOTHER_KEY, ANOTHER_VALUE, THREE_DAYS);

cache.removeAll();
cache.clear();

assertNull(cache.get(A_KEY));
assertNull(cache.get(ANOTHER_KEY));
Expand All @@ -65,7 +65,7 @@ public void sizeWorksAfterRemovingOldElements() {
cache.set(ANOTHER_KEY, ANOTHER_VALUE, THREE_DAYS);
dateProvider.setFixed(twoHoursFromNow());

cache.removeTooOldValues();
cache.purge();

assertNull(cache.get(A_KEY));
assertEquals(ANOTHER_VALUE, cache.get(ANOTHER_KEY));
Expand Down

0 comments on commit e1f0ff0

Please sign in to comment.