=== libs/libmythtv/eitcache.h
==================================================================
--- libs/libmythtv/eitcache.h	(revision 234)
+++ libs/libmythtv/eitcache.h	(revision 238)
@@ -10,6 +10,7 @@
 
 // Qt headers
 #include <qmap.h>
+#include <qmutex.h>
 #include <qstring.h>
 
 typedef QMap<uint64_t, uint64_t> key_map_t;
@@ -20,19 +21,22 @@
     EITCache();
    ~EITCache() {};
 
-    bool IsNewEIT(const uint tsid,       const uint eventid,
-                  const uint serviceid,  const uint tableid,
-                  const uint version,
-                  const unsigned char * const eitdata,
-                  const uint eitlength);
+    bool IsNewEIT(const uint onid, const uint tsid,
+                  const uint serviceid, const uint eventid,
+                  const uint tableid, const uint version, 
+                  const uint endtime);
 
+    uint PruneOldEntries(uint timestamp);
+
     void ResetStatistics(void);
-    QString GetStatistics(void) const;
+    QString GetStatistics(void);
 
   private:
     // event key cache
     key_map_t   eventMap;
 
+    QMutex      eventMapLock;
+
     // statistics
     uint        accessCnt;
     uint        hitCnt;
=== libs/libmythtv/eithelper.cpp
==================================================================
--- libs/libmythtv/eithelper.cpp	(revision 234)
+++ libs/libmythtv/eithelper.cpp	(revision 238)
@@ -210,11 +210,10 @@
     for (uint i = 0; i < eit->EventCount(); i++)
     {
         // Skip event if we have already processed it before...
-        if (!eitcache->IsNewEIT(
-                eit->TSID(),      eit->EventID(i),
-                eit->ServiceID(), eit->TableID(),
-                eit->Version(),
-                eit->Descriptors(i), eit->DescriptorsLength(i)))
+        if (!eitcache->IsNewEIT(eit->OriginalNetworkID(), eit->TSID(),
+                                eit->ServiceID(), eit->EventID(i),
+                                eit->TableID(), eit->Version(),
+                                eit->StartTimeKey(i)+eit->DurationInSeconds(i)))
         {
             continue;
         }
=== libs/libmythtv/eitcache.cpp
==================================================================
--- libs/libmythtv/eitcache.cpp	(revision 234)
+++ libs/libmythtv/eitcache.cpp	(revision 238)
@@ -23,24 +23,25 @@
     verChgCnt = 0;
 }
 
-QString EITCache::GetStatistics(void) const
+QString EITCache::GetStatistics(void)
 {
+    QMutexLocker locker(&eventMapLock);
     return QString(
         "EITCache::statistics: Accesses: %1, Hits: %2, "
-        "Table Upgrades %3, New Versions: %4")
-        .arg(accessCnt).arg(hitCnt).arg(tblChgCnt).arg(verChgCnt);
+        "Table Upgrades %3, New Versions: %4, Entries: %5")
+        .arg(accessCnt).arg(hitCnt).arg(tblChgCnt).arg(verChgCnt).arg(eventMap.size());
 }
 
-static uint64_t construct_key(uint tsid, uint eventid, uint serviceid)
+static uint64_t construct_key(uint onid, uint tsid, uint serviceid, uint eventid)
 {
-    return (((uint64_t) tsid      << 48) | ((uint64_t) eventid   << 32) |
-            ((uint64_t) serviceid << 16));
+    return (((uint64_t) onid      << 48) | ((uint64_t) tsid    << 32) |
+            ((uint64_t) serviceid << 16) | ((uint64_t) eventid      ));
 }
 
-static uint64_t construct_sig(uint tableid, uint version, uint chksum)
+static uint64_t construct_sig(uint tableid, uint version, uint endtime)
 {
     return (((uint64_t) tableid   << 40) | ((uint64_t) version   << 32) |
-            ((uint64_t) chksum));
+            ((uint64_t) endtime));
 }
 
 static uint extract_table_id(uint64_t sig)
@@ -53,15 +54,21 @@
     return (sig >> 32) & 0x1f;
 }
 
-bool EITCache::IsNewEIT(const uint tsid,      const uint eventid,
-                        const uint serviceid, const uint tableid,
-                        const uint version,
-                        const unsigned char * const /*eitdata*/,
-                        const uint /*eitlength*/)
+static uint extract_endtime(uint64_t sig)
 {
+    return sig & 0xffff;
+}
+
+bool EITCache::IsNewEIT(const uint onid, const uint tsid,
+                        const uint serviceid, const uint eventid,
+                        const uint tableid, const uint version, 
+                        const uint endtime)
+{
     accessCnt++;
 
-    uint64_t key = construct_key(tsid, eventid, serviceid);
+    uint64_t key = construct_key(onid, tsid, serviceid, eventid);
+
+    QMutexLocker locker(&eventMapLock);
     key_map_t::const_iterator it = eventMap.find(key);
 
     if (it != eventMap.end())
@@ -87,9 +94,29 @@
         }
     }
 
-    eventMap[key] = construct_sig(tableid, version, 0 /*chksum*/);
+    eventMap[key] = construct_sig(tableid, version, endtime);
 
     return true;
 }
 
+uint EITCache::PruneOldEntries(uint timestamp)
+{
+    QMutexLocker locker(&eventMapLock);
+    uint size = eventMap.size();
+    key_map_t::iterator it = eventMap.begin();
+    while (it != eventMap.end())
+    {
+        if (extract_endtime(*it) < timestamp)
+        {
+            key_map_t::iterator tmp = it;
+            ++tmp;
+            eventMap.erase(it);
+            it = tmp;
+        }
+        else
+            ++it;
+    }
+    return size -  eventMap.size();
+}
+
 /* vim: set expandtab tabstop=4 shiftwidth=4: */
=== programs/mythbackend/eitactivescanner.cpp
==================================================================
--- programs/mythbackend/eitactivescanner.cpp	(revision 234)
+++ programs/mythbackend/eitactivescanner.cpp	(revision 238)
@@ -63,8 +63,9 @@
 
     while (!exitThread)
     {
-        if (ismaster && (QDateTime::currentDateTime() > activeScanNextTrig)
-            && !cardList->isEmpty())
+        QDateTime now = QDateTime::currentDateTime();
+
+        if (ismaster && (now > activeScanNextTrig) && !cardList->isEmpty())
         {
             cerr << eitCache->GetStatistics() << endl;
             if (activeScanNextCard == cardIDToSourceID.end())
@@ -98,7 +99,16 @@
 
             activeScanNextCard++;
         }
-        // TODO: prune old eit cache entries every now and then
+
+        if (now > nextPruneCacheTime)
+        {
+            // prune cache entries that ended more than kPruneCacheTimeOffset ago
+            uint prunedEntries = eitCache->PruneOldEntries(now.addSecs(-kPruneCacheTimeOffset).toTime_t());
+            nextPruneCacheTime.addSecs(kPruneCacheTimeOffset);
+
+            VERBOSE(VB_GENERAL, QString("Pruned %1 entries from the eit cache")
+                        .arg(prunedEntries));
+        }
             
         exitThreadCond.wait(200); // sleep up to 200 ms.
     }
@@ -190,5 +200,6 @@
         activeScanNextTrig = QDateTime::currentDateTime();
         activeScanTrigTime = max_seconds_per_source / cardList->size();
         activeScanNextCard = cardIDToSourceID.begin();
+        nextPruneCacheTime = QDateTime::currentDateTime().addSecs(kPruneCacheTimeOffset);
     }
 }
=== programs/mythbackend/eitactivescanner.h
==================================================================
--- programs/mythbackend/eitactivescanner.h	(revision 234)
+++ programs/mythbackend/eitactivescanner.h	(revision 238)
@@ -48,7 +48,11 @@
     QMap<int, uint>            cardIDToSourceID;
     QMap<int, uint>::iterator  activeScanNextCard;
 
-    bool             ismaster;
+    bool                ismaster;
+
+    QDateTime           nextPruneCacheTime;
+
+    static const int    kPruneCacheTimeOffset = 21600; // six hours
 };
 
 #endif //EITACTIVESCANNER_H
