-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02ede6d
commit 510799f
Showing
3 changed files
with
136 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import Label from '@/components/SimpleLabel' | ||
|
||
const Body = () => { | ||
const listStyle = 'list-disc mx-6 mt-0 mb-5' | ||
|
||
return ( | ||
<> | ||
<p> | ||
A write-back cache is a type of caching mechanism where data | ||
modifications are initially written to the cache rather than directly to | ||
the main database. This approach enhances performance by reducing the | ||
number of direct write operations to the database, as the cached data is | ||
written back to the database at a later time. Write-back caching is | ||
particularly beneficial in high-write frequency applications and | ||
scenarios requiring quick data access and lower latency. However, it | ||
requires careful management to ensure data consistency and integrity, as | ||
there is a risk of data loss if the cache fails before the data is | ||
written to the database. | ||
</p> | ||
|
||
<p className="mt-2"> | ||
<span className="font-bold text-lg">When to Use Write-Back Cache:</span> | ||
</p> | ||
|
||
<ul className={listStyle}> | ||
<li> | ||
<Label text="High Write Frequency" /> When the application has a high | ||
volume of write operations, and performance is critical. The | ||
write-back cache can reduce the number of write operations to the | ||
database, thus improving performance. | ||
</li> | ||
<li> | ||
<Label text="Batch Processing" /> In scenarios where data can be | ||
processed in batches, such as analytics workloads where intermediate | ||
results can be cached and written to the database later. | ||
</li> | ||
<li> | ||
<Label text="Temporary Data Storage" /> When dealing with temporary | ||
data that does not need immediate persistence, such as session data in | ||
a web application. | ||
</li> | ||
<li> | ||
<Label text="Network Latency" /> When the database is hosted on a | ||
remote server, and reducing the number of network calls is beneficial. | ||
</li> | ||
<li> | ||
<Label text="Cost Optimization" /> In cloud environments where | ||
database writes incur cost, reducing the number of direct writes can | ||
lead to cost savings. | ||
</li> | ||
</ul> | ||
|
||
<p className="mt-1"> | ||
<span className="font-bold text-lg"> | ||
When to Avoid Write-Back Cache: | ||
</span> | ||
</p> | ||
|
||
<ul className={listStyle}> | ||
<li> | ||
<Label text="Data Integrity Critical" /> When data integrity is | ||
paramount, and any data loss due to cache failure is unacceptable, | ||
such as in financial transactions. | ||
</li> | ||
<li> | ||
<Label text="Low Write Frequency" /> In applications where write | ||
operations are infrequent, the complexity and potential issues of | ||
write-back caching may not be justified. | ||
</li> | ||
<li> | ||
<Label text="Real-Time Systems" /> For real-time systems where | ||
immediate data availability and consistency are required, such as live | ||
trading platforms. | ||
</li> | ||
<li> | ||
<Label text="High Volatility" /> When data changes frequently and | ||
needs to be immediately reflected across all systems and users, like | ||
collaborative editing tools. | ||
</li> | ||
<li> | ||
<Label text="Simple Architectures" /> In simpler applications where | ||
the overhead of managing a write-back cache might outweigh the | ||
performance benefits. | ||
</li> | ||
</ul> | ||
</> | ||
) | ||
} | ||
|
||
export default Body |
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,40 @@ | ||
'use client' | ||
|
||
import {FC, useEffect, useState} from 'react' | ||
|
||
import {createGoogleGenerativeAI} from '@ai-sdk/google' | ||
import {generateText} from 'ai' | ||
|
||
import Body from './Body' | ||
|
||
export interface Props { | ||
component: string | ||
} | ||
|
||
const Tags: FC<Props> = ({component}) => { | ||
const [aiTags, setPromtPresponse] = useState<Array<string>>([]) | ||
|
||
console.log('Body', Body) | ||
|
||
useEffect(() => { | ||
if (aiTags.length > 0) return | ||
|
||
const google = createGoogleGenerativeAI({ | ||
apiKey: process.env.NEXT_PUBLIC_GOOGLE_AI_KEY, | ||
}) | ||
const model = google('models/gemini-pro') | ||
|
||
generateText({ | ||
model, | ||
prompt: `From the following react component: ${Body} please create five tags. Tags should be return as a plain text seperated with with comma`, | ||
}).then(response => { | ||
const tags = response.text.split(',') | ||
|
||
setPromtPresponse(tags) | ||
}) | ||
}, [aiTags]) | ||
|
||
return <>{aiTags.join(',')}</> | ||
} | ||
|
||
export default Tags |