-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from NicolasConstant/develop
0.9.0 PR
- Loading branch information
Showing
18 changed files
with
157 additions
and
93 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
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
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
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
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
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,52 @@ | ||
using System; | ||
using BirdsiteLive.Twitter.Models; | ||
using Microsoft.Extensions.Caching.Memory; | ||
|
||
namespace BirdsiteLive.Twitter | ||
{ | ||
public class CachedTwitterService : ITwitterService | ||
{ | ||
private readonly ITwitterService _twitterService; | ||
|
||
private MemoryCache _userCache = new MemoryCache(new MemoryCacheOptions() | ||
{ | ||
SizeLimit = 5000 | ||
}); | ||
private MemoryCacheEntryOptions _cacheEntryOptions = new MemoryCacheEntryOptions() | ||
.SetSize(1)//Size amount | ||
//Priority on removing when reaching size limit (memory pressure) | ||
.SetPriority(CacheItemPriority.High) | ||
// Keep in cache for this time, reset time if accessed. | ||
.SetSlidingExpiration(TimeSpan.FromHours(24)) | ||
// Remove from cache after this time, regardless of sliding expiration | ||
.SetAbsoluteExpiration(TimeSpan.FromDays(30)); | ||
|
||
#region Ctor | ||
public CachedTwitterService(ITwitterService twitterService) | ||
{ | ||
_twitterService = twitterService; | ||
} | ||
#endregion | ||
|
||
public TwitterUser GetUser(string username) | ||
{ | ||
if (!_userCache.TryGetValue(username, out TwitterUser user)) | ||
{ | ||
user = _twitterService.GetUser(username); | ||
_userCache.Set(username, user, _cacheEntryOptions); | ||
} | ||
|
||
return user; | ||
} | ||
|
||
public ExtractedTweet GetTweet(long statusId) | ||
{ | ||
return _twitterService.GetTweet(statusId); | ||
} | ||
|
||
public ExtractedTweet[] GetTimeline(string username, int nberTweets, long fromTweetId = -1) | ||
{ | ||
return _twitterService.GetTimeline(username, nberTweets, fromTweetId); | ||
} | ||
} | ||
} |
Oops, something went wrong.