nickpad / timedcache

A simple library for time-based caching of ruby objects.

This URL has Read+Write access

timedcache / misc / thread_test.rb
100644 25 lines (16 sloc) 0.5 kb
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
require File.join(File.dirname(__FILE__), "../lib/timedcache")
 
# This script will almost certainly raise an exception if
# thread safety is not implemented.
 
db = File.join(File.dirname(__FILE__), "thread_test.db")
 
cache = TimedCache.new(:type => :file, :filename => File.join(db))
 
threads = []
 
10.times do
  threads << Thread.new do
    100.times {
      cache.put("thread-safe?", "let's find out")
      cache.get("thread-safe?")
    }
  end
end
 
 
threads.each { |t| t.join }
 
File.delete(db)