Permalink
Browse files

redis handler manually purges pngs

  • Loading branch information...
1 parent 78551d0 commit d0cf653f9b89433cfb9e938d3de4ed57c11ff2bf @technoweenie committed Dec 29, 2009
Showing with 19 additions and 5 deletions.
  1. +18 −5 demos/redis/lib/redis_demo/spark_list.rb
  2. +1 −0 demos/redis/sparkplug_redis.rb
@@ -9,16 +9,23 @@ class SparkList
# :limit => 50
# :redis => {} # passed to Redis
def initialize(options = {})
- @prefix = options[:prefix] || 'plug'
- @limit = options[:limit] || 50
- @index_key = "#{@prefix}:index"
- @redis = Redis.new(options[:redis] || {})
- @plug_list = PlugList.new(self)
+ @cache_path = options[:cache_path]
+ @prefix = options[:prefix] || 'plug'
+ @limit = options[:limit] || 50
+ @index_key = "#{@prefix}:index"
+ @redis = Redis.new(options[:redis] || {})
+ @plug_list = PlugList.new(self)
end
def find(name)
Plug.new(self, name)
end
+
+ def unlink(name)
+ return if !@cache_path
+ plug_cache = File.join(@cache_path, "#{name}.png")
+ File.unlink(plug_cache) if File.exist?(plug_cache)
+ end
end
class PlugList
@@ -64,6 +71,7 @@ def add(value)
excess.times { @redis.lpop(name_key) }
end
self.updated_at = Time.now.utc
+ unlink
end
def datapoints
@@ -80,11 +88,16 @@ def updated_at=(v)
end
def delete
+ unlink
@list.plug_list.delete(self)
@redis.delete(name_key)
@redis.delete(updated_key)
end
+ def unlink
+ @list.unlink(@name)
+ end
+
def exists?
count > 0
end
@@ -22,6 +22,7 @@
{}
end
+config[:cache_path] = File.expand_path(File.join(File.dirname(__FILE__), 'public', 'sparks'))
$redis_list = RedisDemo::SparkList.new(config)
$handler = RedisDemo::Handler.new($redis_list)
pub_dir = File.expand_path(File.join(File.dirname(__FILE__), 'public'))

0 comments on commit d0cf653

Please sign in to comment.