Class: Cachetastic::Adapters::FileBase
- Inherits:
-
Base
show all
- Defined in:
- lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/file_base.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#logger, #name
Instance Method Summary
collapse
Methods inherited from Base
#configuration, configuration, #debug?, #initialize
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
5
6
7
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/file_base.rb', line 5
def directory
@directory
end
|
#hashed_keys ⇒ Object
Returns the value of attribute hashed_keys.
6
7
8
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/file_base.rb', line 6
def hashed_keys
@hashed_keys
end
|
Instance Method Details
#delete(key, delay = 0) ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/file_base.rb', line 33
def delete(key, delay = 0)
if delay <= 0
FileUtils.rm_rf(get_key_directoy(key), :verbose => self.debug?)
else
so = self.get(key)
if so
self.set(so.key, so.value, delay)
end
end
end
|
#expire_all ⇒ Object
44
45
46
47
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/file_base.rb', line 44
def expire_all
FileUtils.rm_rf(self.directory, :verbose => self.debug?)
setup
end
|
8
9
10
11
12
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/file_base.rb', line 8
def setup
@directory = File.join(self.configuration.store_options.dir, self.name.to_s)
FileUtils.mkdir_p(self.directory, :verbose => self.debug?)
@hashed_keys = {}
end
|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/file_base.rb', line 18
def stats
super
num_files = num_directories = file_size = 0
everything = Dir.glob("#{self.directory}/**/*")
everything.reject{|x| x =~ /^\./}.each do |entry|
if ::File.directory?(entry)
num_directories += 1
else
file_size += ::File.size(entry)
num_files += 1
end
end
puts "Number of Files: #{num_files}\nNumber of Directories: #{num_directories}\nTotal Size on Disk: #{file_size/1024.to_f} KB\n\n"
end
|
#valid? ⇒ Boolean
14
15
16
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/file_base.rb', line 14
def valid?
File.exists?(self.directory)
end
|