# Memory-resident variable question

**URL:** <https://community.f5.com/t/memory-resident-variable-question/5841>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [August 23, 2007, 11:03pm UTC](https://community.f5.com/t/memory-resident-variable-question/5841 "2007-08-23T23:03:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chad\_Roberts\_21](https://avatars.discourse-cdn.com/v4/letter/c/b4bc9f/32.png) [@Chad\_Roberts\_21](https://community.f5.com/u/Chad_Roberts_21)\
**Post date:** [August 23, 2007, 11:03pm UTC](https://community.f5.com/t/memory-resident-variable-question/5841/1 "2007-08-23T23:03:06Z")

</div>

I need to write an iRule that will track what cookie values are assigned by the back end servers and to which user IDs and store them for a certain period of time. This is a multi-part problem, and I don’t know where to begin.

1. A global variable is one thing, but how do you dynamically create and maintain a table?

2. How can I keep a counter on the age of a value in this table and remove it after, say, 60 minutes?

My thought is that I could have three sets of values in the table: one with cookie values, the second with corresponding user IDs (which I’ll extract from the payload), and the third with a clock scan at the time I add the values. I’ll just have to add some logic somewhere else to clean up or something.

Thoughts? Is there an easier way?

---

<div class="post-metadata">

**Author:** ![Deb\_Allen\_18](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@Deb\_Allen\_18](https://community.f5.com/u/Deb_Allen_18)\
**Post date:** [August 24, 2007, 1:47am UTC](https://community.f5.com/t/memory-resident-variable-question/5841/2 "2007-08-24T01:47:13Z")

</div>

1. session command

2. session command

3. [Click here](http://devcentral.f5.com/wiki/default.aspx/iRules.session)

```tcl
when HTTP_REQUEST {
   Don't allow data to be chunked
  if { [HTTP::version] eq "1.1" } {
    if { [HTTP::header is_keepalive] } {
      HTTP::header replace "Connection" "Keep-Alive"
    }
     HTTP::version "1.0"
  }
}
when HTTP_RESPONSE {
  if {[HTTP::cookie exists myCookie]}{
     trigger collection for up to 1MB of data if cookie exists
    if {([HTTP::header exists "Content-Length"]) && ([HTTP::header "Content-Length"] <= 1000000)}{
      set content_length [HTTP::header "Content-Length"]
    } else {
        set content_length 1000000
    }
    if { $content_length > 0 } {
      HTTP::collect $content_length
    }
  }
}
when HTTP_RESPONSE_DATA {
   grab client ID to use as session table entry key
  set clientID [findstr [HTTP::payload] "clientID=" 9 &]
  if {$clientID != ""}{
     if key value found, add session table entry with 300 sec timeout
    session add uie $clientID [HTTP::cookie myCookie] 300
  }
}

```

HTH

/deb

---

<div class="post-metadata">

**Author:** ![Chad\_Roberts\_21](https://avatars.discourse-cdn.com/v4/letter/c/b4bc9f/32.png) [@Chad\_Roberts\_21](https://community.f5.com/u/Chad_Roberts_21)\
**Post date:** [August 27, 2007, 8:28pm UTC](https://community.f5.com/t/memory-resident-variable-question/5841/3 "2007-08-27T20:28:57Z")

</div>

Thanks, deb. That got me going.
