Module: Catche::Tag

Extended by:
Tag
Included in:
Tag
Defined in:
lib/catche/tag.rb,
lib/catche/tag/collect.rb

Defined Under Namespace

Classes: Collect

Constant Summary collapse

KEY =
'catche'
DIVIDER =
'_'

Instance Method Summary collapse

Instance Method Details

#expire!(*tags) ⇒ Object



53
54
55
56
57
58
# File 'lib/catche/tag.rb', line 53

def expire!(*tags)
  tags.each do |tag|
    Catche::Expire.expire! fetch_tag(tag)
    Catche.adapter.delete stored_key(:tags, tag)
  end
end

#join(*tags) ⇒ Object



11
12
13
# File 'lib/catche/tag.rb', line 11

def join(*tags)
  tags.flatten.compact.uniq.join(DIVIDER)
end

#tag_page!(page, *tags) ⇒ Object

Tags a page cache



22
23
24
# File 'lib/catche/tag.rb', line 22

def tag_page!(page, *tags)
  tag_type! :pages, page, *tags
end

#tag_type!(scope, value, *tags) ⇒ Object

Dynamic method for tagging a type of stored cache

Catche::Tag.tag_type!(:views, 'example.com/projects', 'projects')


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/catche/tag.rb', line 29

def tag_type!(scope, value, *tags)
  tags.each do |tag|
    data      = fetch_tag(tag)

    # Set up key names
    tag_key   = stored_key(:tags, tag)
    type_key  = stored_key(scope, value)

    # Current tags
    type_tags = fetch_type(scope, value)

    # Append new value to scoped data
    data[scope] ||= []
    data[scope] << value
    tag_data  = data

    # Append new tag key
    type_data = type_tags << tag_key

    Catche.adapter.write(tag_key, tag_data)
    Catche.adapter.write(type_key, type_data)
  end
end

#tag_view!(view, *tags) ⇒ Object Also known as: tag_fragment!

Tags a view



16
17
18
# File 'lib/catche/tag.rb', line 16

def tag_view!(view, *tags)
  tag_type! :views, view, *tags
end