-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check with webapps this is on right lines
- Loading branch information
Simon Emms
committed
Mar 8, 2022
1 parent
fa9e838
commit 8fdfc65
Showing
4 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License-AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { injectable } from 'inversify'; | ||
|
||
@injectable() | ||
export class UserCounter { | ||
public expires: Date | null = null; | ||
|
||
protected data: number | null = null; | ||
|
||
protected readonly timeout: number = 60 * 1000; // Cache data for 1 minute | ||
|
||
get count(): number | null { | ||
if (this.expires !== null && Date.now() >= this.expires.getTime()) { | ||
// The timestamp is in range - return the data | ||
console.log('getting cached data', this.data); | ||
return this.data; | ||
} | ||
// Not in range - return null | ||
return null; | ||
} | ||
|
||
set count(userCount: number | null) { | ||
this.expires = new Date(Date.now() + this.timeout); | ||
|
||
this.data = userCount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters