-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
53 lines (36 loc) · 1.82 KB
/
README
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
System Lock
===========
System Lock is a system-wide critical section for ruby code. This works across multiple mongrel/thin instances
across multiple servers. This also works with recursive calls to the lock by using reference counting. The
information required for the lock is stored in memcached.
Requirements
============
Memcached Server
Dalli Gem
What you need to know
====================
1) Set this after you initialize memcached. CACHE is the instance of
DALLI e.g. "CACHE = Dalli::Client.new(SERVER_LIST, {:username = "XXXXXX", :password => "XXXXXX"})"
Internaut::SystemLock.memcached_instance = CACHE
If you are in Rails you can use the following in your environment.rb:
Internaut::SystemLock.memcached_instance = Rails.cache
2) Setup your lock around the code you want to protect. The unique identifier should be something that identifies
not only the code block, but in which cases you want it to be protected. For example, in this case I am using
something that looks like a route or url. I want to protect this code block for all users trying to access
project id 152.
Internaut::SystemLock.critical_section('/projects/152') do
# any code that you execute in here will be serialized as long
# as it has the same unique code block identifier
end
API
===
Internaut::SystemLock.memcached_instance(MEMCACHED_INSTANCE)
Internaut::SystemLock.critical_section(unique_code_block_identifier, timeout=60)
# Timeout default 60 seconds. Set it higher than you need it to be.
Internaut::SystemLock.disable!
Internaut::SystemLock.enable! (enabled by default)
Internaut::SystemLock.enabled?
Information stored in Memcached
===============================
unique_code_block_identifier => [ process_id + unique_server_id_string, reference_count ]
Copyright (c) 2009 Rodney Carvalho, released under the MIT license