~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to plugins/experimental/lua/examples/cachestatus.lua

  • Committer: Package Import Robot
  • Author(s): Aron Xu
  • Date: 2013-05-09 01:00:04 UTC
  • mto: (1.1.11) (5.3.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: package-import@ubuntu.com-20130509010004-9fqq9n0adseg3f8w
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--  Licensed to the Apache Software Foundation (ASF) under one
 
2
--  or more contributor license agreements.  See the NOTICE file
 
3
--  distributed with this work for additional information
 
4
--  regarding copyright ownership.  The ASF licenses this file
 
5
--  to you under the Apache License, Version 2.0 (the
 
6
--  "License"); you may not use this file except in compliance
 
7
--  with the License.  You may obtain a copy of the License at
 
8
--
 
9
--  http://www.apache.org/licenses/LICENSE-2.0
 
10
--
 
11
--  Unless required by applicable law or agreed to in writing, software
 
12
--  distributed under the License is distributed on an "AS IS" BASIS,
 
13
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
--  See the License for the specific language governing permissions and
 
15
--  limitations under the License.
 
16
 
 
17
-- Lua example to log the HTTP transaction cache lookup status.
 
18
 
 
19
require 'string'
 
20
require 'debug'
 
21
 
 
22
ts = require 'ts'
 
23
ts.hook = require 'ts.hook'
 
24
 
 
25
ts.debug('cachestatus', string.format('loaded %s', debug.getinfo(1).source))
 
26
 
 
27
do
 
28
 
 
29
local strings = { }
 
30
strings[ts.CACHE_LOOKUP_MISS]       = "TS_CACHE_LOOKUP_MISS"
 
31
strings[ts.CACHE_LOOKUP_HIT_STALE]  = "TS_CACHE_LOOKUP_HIT_STALE"
 
32
strings[ts.CACHE_LOOKUP_HIT_FRESH]  = "TS_CACHE_LOOKUP_HIT_FRESH"
 
33
strings[ts.CACHE_LOOKUP_SKIPPED]    = "TS_CACHE_LOOKUP_SKIPPED"
 
34
 
 
35
function cachestatus(status)
 
36
    return strings[status]
 
37
end
 
38
end
 
39
 
 
40
ts.hook.register(ts.hook.HTTP_CACHE_LOOKUP_COMPLETE_HOOK,
 
41
    function(event, txn)
 
42
        ts.debug('cachestatus',
 
43
            string.format('cache lookup status is %s', cachestatus(txn:cachestatus())))
 
44
        txn:continue()
 
45
    end
 
46
)
 
47
 
 
48
-- vim: set sw=4 ts=4 et :