File pcache-2.0.0-git.patch of Package pcache
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..03e5e39
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,9 @@
+language: erlang
+notifications:
+ email: false
+otp_release:
+ - 17.4
+ - 17.1
+ - 17.0
+ - R16B03-1
+ - R15B03
diff --git a/README.md b/README.md
index 22e6bf5..621c1dc 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,8 @@
pcache: Erlang Process Based Cache
==================================
+[](http://travis-ci.org/mattsta/pcache)
+
pcache uses erlang processes to auto-expire cache items.
pcache is an improved version of the cache described in http://duomark.com/erlang/publications/acm2006.pdf
diff --git a/src/pcache_reaper.erl b/src/pcache_reaper.erl
index ccfcde6..cb3fd1c 100644
--- a/src/pcache_reaper.erl
+++ b/src/pcache_reaper.erl
@@ -25,27 +25,18 @@ start(CacheName, CacheSize) ->
%%%----------------------------------------------------------------------
shrink_cache_to_size(_Name, CurrentCacheSize, CacheSize)
- when CurrentCacheSize < CacheSize ->
+ when CurrentCacheSize =< CacheSize ->
ok;
shrink_cache_to_size(Name, _CurrentCacheSize, CacheSize) ->
gen_server:call(Name, reap_oldest),
shrink_cache_to_size(Name, pcache:total_size(Name), CacheSize).
-
pcache_reaper(Name, CacheSize) ->
% sleep for 4 seconds
- receive
- after 4000 -> ok
- end,
+ timer:sleep(4000),
% Lame. Account for sizes better. total_size asks every datum for its size.
CurrentCacheSize = pcache:total_size(Name),
- if
- CurrentCacheSize < CacheSize -> ok;
- CurrentCacheSize >= CacheSize ->
-%io:format("Cache ~p too big! Shrinking...~n", [self()]),
-%io:format("CurrentSize: ~p; Target Size: ~p~n", [CurrentCacheSize, CacheSize]),
- shrink_cache_to_size(Name, CurrentCacheSize, CacheSize)
- end,
+ shrink_cache_to_size(Name, CurrentCacheSize, CacheSize),
pcache_reaper(Name, CacheSize).
init([Name, CacheSizeBytes]) ->
diff --git a/src/pcache_server.erl b/src/pcache_server.erl
index e28d74a..11e7990 100644
--- a/src/pcache_server.erl
+++ b/src/pcache_server.erl
@@ -287,15 +287,16 @@ launch_memoize_datum(Key, EtsIndex, Module, Accessor, TTL, CachePolicy) ->
update_ttl(#datum{started = Started, ttl = TTL,
type = actual_time} = Datum) ->
+ Timestamp = os:timestamp(),
% Get total time in seconds this datum has been running. Convert to ms.
- StartedNowDiff = timer:now_diff(os:timestamp(), Started) div 1000,
+ StartedNowDiff = timer:now_diff(Timestamp, Started) div 1000,
% If we are less than the TTL, update with TTL-used (TTL in ms too)
% else, we ran out of time. expire on next loop.
TTLRemaining = if
StartedNowDiff < TTL -> TTL - StartedNowDiff;
true -> 0
end,
- Datum#datum{last_active = os:timestamp(), remaining_ttl = TTLRemaining};
+ Datum#datum{last_active = Timestamp, remaining_ttl = TTLRemaining};
update_ttl(Datum) ->
Datum#datum{last_active = os:timestamp()}.