@election.voters.each do |voter|
next unless voter.ipaddress
location=nil
- if Cache and location=Cache.get("GEO:#{voter.ipaddress}")
- elsif Cache
+ if defined? Cache and location=Cache.get("GEO:#{voter.ipaddress}")
+ elsif defined? Cache
location = GeoKit::Geocoders::IpGeocoder.geocode(voter.ipaddress)
Cache.set "GEO:#{voter.ipaddress}", location
else
#Calculate results if not in memcache
def results
# Assignment is intentional
- if Cache and c = Cache.get("election_results:#{id}:#{self.votes.length}")
+ if defined? Cache and c = Cache.get("election_results:#{id}:#{self.votes.length}")
@plurality_result = c['plurality']
@approval_result = c['approval']
@condorcet_result = c['condorcet']
@ssd_result = c['ssd']
@borda_result = c['borda']
return c
- elsif Cache
+ elsif defined? Cache
# memcache is available, but missed.
results = self.results!
Cache.set("election_results:#{id}:#{self.votes.length}", results)
voter.ipaddress =~ /^172\.[1-3]/
%>
<% w=nil
- if Cache and w=Cache.get("WHOIS:#{voter.ipaddress}")
- elsif Cache
+ if defined? Cache and w=Cache.get("WHOIS:#{voter.ipaddress}")
+ elsif defined? Cache
w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true)
w.search_whois
Cache.set("WHOIS:#{voter.ipaddress}", w)
# Settings specified here will take precedence over those in config/environment.rb
#
#Enable memcache
-require('memcache')
-Cache=MemCache.new('localhost', :compression => true)
+#require('memcache')
+#Cache=MemCache.new('localhost', :compression => true)
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true