File tree Expand file tree Collapse file tree 4 files changed +43
-4
lines changed Expand file tree Collapse file tree 4 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ ACNodeClient
32
32
#include " card.h"
33
33
#include " sdcache.h"
34
34
#include " eepromcache.h"
35
- #include " nocache .h"
35
+ #include " ramcache .h"
36
36
#include " doorbot.h"
37
37
#include " doorbot_ac.h"
38
38
@@ -109,8 +109,8 @@ void setup() {
109
109
Serial.println (" Using the SD Card to cache cards" );
110
110
} else {
111
111
Serial.println (" SD card could not be accessed" );
112
- Serial.println (" Please fix the SD card and try again. Cache is disabled until reboot ." );
113
- cache = new NoCache ();
112
+ Serial.println (" Please fix the SD card and try again. Caching cards in RAM for now ." );
113
+ cache = new RAMCache ();
114
114
}
115
115
} else {
116
116
Serial.println (" Using the eeprom to cache cards" );
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ void Cache::fill(const int count) {
21
21
}
22
22
23
23
void list_callback (Card c) {
24
+ wdog.feed ();
24
25
c.dump ();
25
26
}
26
27
@@ -30,4 +31,3 @@ void Cache::list(void) {
30
31
Serial.print (count);
31
32
Serial.println (" users" );
32
33
}
33
-
Original file line number Diff line number Diff line change 1
1
#include " ramcache.h"
2
2
#include " network.h"
3
+ #include " watchdog.h"
4
+
5
+ extern Watchdog wdog;
3
6
4
7
CacheEntry::CacheEntry () :
5
8
expires_at(0 ),
@@ -26,6 +29,8 @@ void CacheEntry::expire() {
26
29
}
27
30
28
31
void RAMCache::begin () {
32
+ Serial.println (" RAM Cache TTL: " + String (CACHE_TTL));
33
+ Serial.println (" RAM Cache memory: " + String (sizeof (CacheEntry) * CACHE_CAPACITY));
29
34
purge ();
30
35
}
31
36
@@ -88,6 +93,7 @@ void RAMCache::verify() {
88
93
for (int i = 0 ; i < CACHE_CAPACITY; i++) {
89
94
CacheEntry *entry = &entries[i];
90
95
if (!entry->expired (now)) {
96
+ wdog.feed ();
91
97
int status = networking::querycard (entry->card );
92
98
switch (status) {
93
99
case 2 :
Original file line number Diff line number Diff line change
1
+ #ifndef _RAMCACHE_H
2
+ #define _RAMCACHE_H
3
+
4
+ #include " cache.h"
5
+ #include " card.h"
6
+
7
+ #define CACHE_TTL 8 * 3600 * 1000 // eight hours
8
+ #define CACHE_CAPACITY 1500
9
+
10
+ class CacheEntry {
11
+ public:
12
+ CacheEntry ();
13
+ CacheEntry (Card c);
14
+ bool expired (unsigned long now);
15
+ void expire ();
16
+ void touch (unsigned long now);
17
+ unsigned long expires_at;
18
+ Card card;
19
+ };
20
+
21
+ class RAMCache : public Cache {
22
+ public:
23
+ virtual void begin ();
24
+ virtual Card get (Card u);
25
+ virtual void set (const Card u);
26
+ virtual void purge (void );
27
+ virtual int each (void ( *callback)(Card c));
28
+ virtual void verify (void );
29
+ private:
30
+ CacheEntry entries[CACHE_CAPACITY];
31
+ };
32
+
33
+ #endif
You can’t perform that action at this time.
0 commit comments